Skip to content

Commit ee32d4d

Browse files
author
Ram swaroop
committed
added questions
1 parent 18e7beb commit ee32d4d

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

_posts/2015-05-14-variables-and-literals.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,8 @@ explicitly initialize them with a value.
482482

483483
### Q&A
484484

485-
__Q1.__
485+
__Q1.__ Given the below program:
486+
486487
{% highlight java linenos %}
487488
public class Fishing {
488489
byte b1 = 4;
@@ -502,7 +503,7 @@ C. Line C
502503
D. Line D
503504
E. Line E
504505

505-
__Q2.__
506+
__Q2.__ Given the below program:
506507

507508
{% highlight java linenos %}
508509
class Mixer {
@@ -537,4 +538,34 @@ B. hi hi
537538
C. hi hi hi
538539
D. Compilation fails
539540
E. hi, followed by an exception
540-
F. hi hi, followed by an exception
541+
F. hi hi, followed by an exception
542+
543+
__Q3.__ Given the below program:
544+
545+
{% highlight java linenos %}
546+
class Fizz {
547+
int x = 5;
548+
549+
public static void main(String[] args) {
550+
final Fizz f1 = new Fizz();
551+
Fizz f2 = new Fizz();
552+
Fizz f3 = FizzSwitch(f1, f2);
553+
System.out.println((f1 == f3) + " " + (f1.x == f3.x));
554+
}
555+
556+
static Fizz FizzSwitch(Fizz x, Fizz y) {
557+
final Fizz z = x;
558+
z.x = 6;
559+
return z;
560+
}
561+
}
562+
{% endhighlight %}
563+
564+
What is the result?
565+
A. true true
566+
B. false true
567+
C. true false
568+
D. false false
569+
E. Compilation fails
570+
F. An exception is thrown at runtime
571+

0 commit comments

Comments
 (0)