| Mock Exam – Nested Classes |
| Q1 |
public class Test1{ private static int i = 10; static class Inner extends Test1{ int i; public void method(){ System.out.println(i); } } public static void main(String args[]){ new Test10.Inner().method(); } } which of the following statement in //? will print “Inner class”? |
| A1 | 10 |
| A2 | 0 |
| A3 | nothing is printed. |
| A4 | Compiler error. |
| Q2 |
which of the following modifiers are applied to the nested classes class? |
| A1 | private |
| A2 | protected |
| A3 | public |
| A4 | static |
| A5 | All the above. |
| Q3 |
which of the following modifiers are applied to the top level classes ? |
| A1 | static |
| A2 | private |
| A3 | strictfp |
| A4 | abstract |
| A5 | All the above. |
| Q4 | which modifer is uesd to stop overridding a method? |
| A1 | final |
| A2 | static |
| A3 | abstract |
| A4 | None of the above. |
| Q5 |
public abstract final class Test5{ public static void main(String args[]){ System.out.println(“Modifiers”); } } what will be the output?
|
| A1 | Modifiers |
| A2 | Compiler error |
| A3 | exception thrown at runtime |
| A4 | None of the above |
| Q6 | which of the following are valid syntax for a toplevel class? |
| A1 | public static class Test6{} |
| A2 | public abstrct class Test6{} |
| A3 | private final class Test6{} |
| A4 | public final class Test6{} |
| Q7 | which of the following are valid syntax for nested classes? |
| A1 | private final abstract class Test7{} |
| A2 | private final class Test7{} |
| A3 | private static class Test7{} |
| A4 | protected abstract class Test7{} |
| Q8 |
public class Test8{ class Inner{ public void method(){ System.out.println(“Inner class”); } } public static void main(String args[]){ // ? } } which of the following statement in //? will print “Inner class”? |
| A1 | new Test8.Inner().method(); |
| A2 | new Test8().Inner().method(); |
| A3 | new Test8.Inner.method(); |
| A4 | Compiler error. |
| Q9 |
public class Test9{ static class Inner{ public void method(){ System.out.println(“Inner class”); } } public static void main(String args[]){ // ? } } which of the following statement in //? will print “Inner class”? |
| A1 | new Test9.Inner().method(); |
| A2 | new Test9().Inner().method(); |
| A3 | new Test9.Inner.method(); |
| A4 | Compiler error. |
| Q10 |
which of the following modifiers are applied to local classes(classses inside method)?. |
| A1 | private |
| A2 | public |
| A3 | protected |
| A4 | None of the above. |
| Answers |
| 1 | new Test8.Inner().method();. |
| 2 | All the above. |
| 3 |
strictfp abstract |
| 4 | final |
| 5 | Compiler error |
| 6 |
public abstrct class Test6{} public final class Test6{} |
| 7 |
private final class Test7{} private static class Test7{} protected abstract class Test7{} |
| 8 | Compiler error. |
| 9 | new Test8.Inner().method();. |
| 10 | None of the above |