java-programming-inner-classes Related Question Answers

1. class Foo { class Bar{ } } class Test { public static void main (String [] args) { Foo f = new Foo(); / Line 10: Missing statement ? / } } which statement, inserted at line 10, creates an instance of Bar?





2. public class MyOuter { public static class MyInner { public static void foo() { } } } which statement, if placed in a class other than MyOuter or MyInner, instantiates an instance of the nested class?





3. What will be the output of the program? public class Foo { Foo() { System.out.print("foo"); } class Bar { Bar() { System.out.print("bar"); } public void go() { System.out.print("hi"); } } / class Bar ends / public static void main (String [] args) { Foo f = new Foo(); f.makeBar(); } void makeBar() { (new Bar() {}).go(); } }/ class Foo ends /





4. What will be the output of the program? public class HorseTest { public static void main (String [] args) { class Horse { public String name; / Line 7 / public Horse(String s) { name = s; } } / class Horse ends / Object obj = new Horse("Zippo"); / Line 13 / Horse h = (Horse) obj; / Line 14 / System.out.println(h.name); } } / class HorseTest ends /





5. What will be the output of the program? public class TestObj { public static void main (String [] args) { Object o = new Object() / Line 5 / { public boolean equals(Object obj) { return true; } } / Line 11 / System.out.println(o.equals("Fred")); } }





6. What will be the output of the program? public abstract class AbstractTest { public int getNum() { return 45; } public abstract class Bar { public int getNum() { return 38; } } public static void main (String [] args) { AbstractTest t = new AbstractTest() { public int getNum() { return 22; } }; AbstractTest.Bar f = t.new Bar() { public int getNum() { return 57; } }; System.out.println(f.getNum() + " " + t.getNum()); } }





7. Which is true about an anonymous inner class?





8. class Boo { Boo(String s) { } Boo() { } } class Bar extends Boo { Bar() { } Bar(String s) {super(s);} void zoo() { // insert code here } } which one create an anonymous inner class from within class Bar?





9. Which is true about a method-local inner class?





10. Which statement is true about a static nested class?




11. Which constructs an anonymous inner class instance?





Terms And Service:We do not guarantee the accuracy of available data ..We Provide Information On Public Data.. Please consult an expert before using this data for commercial or personal use | Powered By:Omega Web Solutions
© 2002-2017 Omega Education PVT LTD...Privacy | Terms And Conditions
Question ANSWER With Solution