File tree Expand file tree Collapse file tree 2 files changed +85
-4
lines changed
Expand file tree Collapse file tree 2 files changed +85
-4
lines changed Original file line number Diff line number Diff line change @@ -316,11 +316,11 @@ class Horse extends Animal {
316316
317317Figure out which version of ` eat() ` will run on each of the invocation made?
318318
319- 1 . Animal ah = new Horse();
319+ A . Animal ah = new Horse();
320320 ah.eat();
321- 2 . Horse he = new Horse();
321+ B . Horse he = new Horse();
322322 he.eat("Apples");
323- 3 . Animal a2 = new Animal();
323+ C . Animal a2 = new Animal();
324324 a2.eat("treats");
325- 4 . Animal ah2 = new Horse();
325+ D . Animal ah2 = new Horse();
326326 ah2.eat("Carrots");
Original file line number Diff line number Diff line change @@ -453,3 +453,84 @@ B. Zippo
453453C. Compilation fails because of an error on line 3
454454D. Compilation fails because of an error on line 9
455455E. Compilation fails because of an error on line 10
456+
457+ __ Q2.__
458+
459+ {% highlight java linenos %}
460+ public abstract class AbstractTest {
461+ public int getNum() {
462+ return 45;
463+ }
464+
465+ public abstract class Bar {
466+ public int getNum() {
467+ return 38;
468+ }
469+ }
470+
471+ public static void main(String[] args) {
472+ AbstractTest t = new AbstractTest() {
473+ public int getNum() {
474+ return 22;
475+ }
476+ };
477+ AbstractTest.Bar f = t.new Bar() {
478+ public int getNum() {
479+ return 57;
480+ }
481+ };
482+ System.out.println(f.getNum() + " " + t.getNum());
483+ }
484+ }
485+ {% endhighlight %}
486+
487+
488+ What is the output?
489+
490+ A. 57 22
491+ B. 45 38
492+ C. 45 57
493+ D. An exception occurs at runtime
494+ E. Compilation fails
495+
496+ __ Q3.__
497+
498+ {% highlight java linenos %}
499+ class A {
500+ void m() {
501+ System.out.println("outer");
502+ }
503+ }
504+
505+ public class MethodLocalVSInner {
506+
507+ public static void main(String[] args) {
508+ new MethodLocalVSInner().go();
509+ }
510+
511+ void go() {
512+ new A().m();
513+ class A {
514+ void m() {
515+ System.out.println("inner");
516+ }
517+ }
518+ }
519+
520+ class A {
521+ void m() {
522+ System.out.println("middle");
523+ }
524+ }
525+ }
526+ {% endhighlight %}
527+
528+ This is an interesting [ question] ( http://stackoverflow.com/questions/29620714/method-local-inner-class-vs-inner-class ) ,
529+ so think and tell what is the output?
530+
531+ A. inner
532+ B. outer
533+ C. middle
534+ D. Compilation fails
535+ E. An exception is thrown at runtime
536+
You can’t perform that action at this time.
0 commit comments