1 . What will be the output?
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(); } }
Choose the one below:
- 10
- 0
- Nothing is printed
- Compiler error
2 . which of the following modifiers are applied to the nested classes class?
- private
- protected
- public
- static
- All the above
3 . which of the following modifiers are applied to the top level classes?
- static
- private
- strictfp
- abstract
- All the above
4 . which modifer is uesd to stop overridding a method?
- final
- static
- abstract
- None of the above
5 . What will be the output?
public abstract final class Test5{ public static void main(String args[]){ System.out.println("Modifiers"); } }
Choose the one below:
- Modifiers
- Compiler error
- Exception thrown at runtime
- None of the above
6 . which of the following are valid syntax for a toplevel class?
- public static class Test6{}
- public abstrct class Test6{}
- private final class Test6{}
- public final class Test6{}
7 . which of the following are valid syntax for nested classes?
- private final abstract class Test7{}
- private final class Test7{}
- private static class Test7{}
- protected abstract class Test7{}
8 . What will be the output?
public class Test8{ class Inner{ public void method(){ System.out.println("Inner class"); } } public static void main(String args[]){ // ? } }
Choose the one below:
- new Test8.Inner().method();
- new Test8().Inner().method();
- new Test8.Inner.method();
- Compiler error
9 . What will be the output?
public class Test9{ static class Inner{ public void method(){ System.out.println("Inner class"); } } public static void main(String args[]){ // ? } }
Choose the one below:
- new Test9.Inner().method();
- new Test9().Inner().method();
- new Test9.Inner.method();
- Compiler error
10 . which of the following modifiers are applied to local classes(classses inside method)?
- private
- public
- protected
- None of the above
Answers
1 : 3 is correct.
2 : 5 is correct. All the above.
3 : 3 & 4 is correct.
3 . strictfp
4 . abstract
4 : 1 is correct. final.
5 : 2 is correct. Compiler error.
6 : 2 & 4 is correct.
2 . public abstrct class Test6{}
4 . public final class Test6{}
7 : 2,3 & 4 is correct.
2 . private final class Test7{}
3 . private static class Test7{}
4 . protected abstract class Test7{}
8 : 4 is correct. Compiler error.
9 : 1 is correct. new Test9.Inner().method();.
10 : 4 is correct. None of the above.