7.1 |
What will be the result of attempting to compile and run the following code? public class MyClass { public static void main(String[] args) { Outer objRef = new Outer(); System.out.println(objRef.createInner().getSecret()); } } class Outer { private int secret; Outer() { secret = 123; } class Inner { int getSecret() { return secret; } } Inner createInner() { return new Inner(); } } Select the one correct answer.
|
7.2 |
Which statements are true about nested classes? Select the two correct answers.
|
7.3 |
What will be the result of attempting to compile and run the following code? public class MyClass { public static void main(String[] args) { State st = new State(); System.out.println(st.getValue()); State.Memento mem = st.memento(); st.alterValue(); System.out.println(st.getValue()); mem.restore(); System.out.println(st.getValue()); } public static class State { protected int val = 11; int getValue() { return val; } void alterValue() { val = (val + 7) % 31; } Memento memento() { return new Memento(); } class Memento { int val; Memento() { this.val = State.this.val; } void restore() { ((State) this).val = this.val; } } } } Select the one correct answer.
|
7.4 |
What will be the result of attempting to compile and run the following program? public class Nesting { public static void main(String[] args) { B.C obj = new B().new C(); } } class A { int val; A(int v) { val = v; } } class B extends A { int val = 1; B() { super(2); } class C extends A { int val = 3; C() { super(4); System.out.println(B.this.val); System.out.println(C.this.val); System.out.println(super.val); } } } Select the one correct answer.
|
7.5 |
Which statements are true about the following program? public class Outer { public void doIt() { } public class Inner { public void doIt() { } } public static void main(String[] args) { new Outer().new Inner().doIt(); } } Select the two correct answers.
|