Java Quiz 13: Passing Objects to a Method

综合编程 2018-03-13

Before we start with this week's quiz, here is the answer to Java Quiz 12: Unary Operators

  1. The statement if(a == a++) returns true because the value of a
    is incremented by one after the evaluation.

  2. The statement a += 3; increments the value of a
    by 3.

  3. The statement System.out.print(a++ + ++a + a++); prints the sum of a++, ++a and a-- to the standard output. a++ = 4, ++a = 6, because the value of a

    is incremented by one a step before. The value of the last a-- remains 6. The statement writes 4 + 6 + 6 = 16 to the standard output.

    The correct answer is: D

Here is the quiz for today!

What is the output of the following code?

public class MyClass
public static void myMethod(StringBuilder s1, StringBuilder s2)
s1 = s2;
public static void main(String[] args)
StringBuilder sb = new StringBuilder("p");
StringBuilder sb2 = new StringBuilder("q");
myMethod(sb, sb2);
System.out.print(sb + ", " + sb2);

Select the correct answer

  • A. This program writes "qs, qs" to the standard output.

  • B. This program writes "pr, qs" to the standard output.

  • C. This program writes "pr, pr" to the standard output.

  • D. This program writes "r, s" to the standard output.

  • E. This program writes "p, q" to the standard output.

  • F. Runtime error.

  • G. Compilation error.

The correct answer and its explanation will be included in the next quiz in two weeks! For more Java quizzes, puzzles, and assignments take a look at my site!


Java基础(四)-异常处理机制及其设计 本篇主要是记录自己所理解的Java异常处理机制(基于jdk1.7)以及怎么去处理和设计异常。还记得当初学习Java异常这块的时候都没怎么注意它的用途,以为就是简单的处理下异常,我避免程序出现这样错误就行了(当初真的很懵懂很天真)。当踏入社会工作后才知道一个好的异常处理框架是有多重要,比方说当你的项目...
美好或者丑陋的 Go 这是一个“ Go不好 ”系列的额外文章。Go确实有一些不错的特性,也就是本文中“好的”部分,但是当我们不使用API或者网络服务器(这是为它设计的)而且将它用于业务领域逻辑的时候,总体而言我发现它用起来笨重且糟糕。但是即使在用于网络编程的时候,在设计和实现方面它也有很多缺陷,这导致它在显而...
Jython and it’s java.nio.charset.UnsupportedCharse... I have been working on an Extender for Burp Suite (a local proxy which allows you to check for common problems and security weaknesses). While the pro...
Java and C hit all-time lows in Tiobe language pop... Java and C continue to lead the Tiobe index of programming language popularity , but both dropped to all-time lows in the just-published August re...
Obtain an entry from the user’s console R... Obtain a matrix from the user? C Programming My console keeps on crashing after entering a few numbers. I am trying to get an ar...
Eclipse Zone

责编内容来自:Eclipse Zone (本文源链)
本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。