OCPJP 6 Mock Exam -19

SHARE & COMMENT :

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:

  1. 10
  2. 0
  3. Nothing is printed
  4. Compiler error

2 . which of the following modifiers are applied to the nested classes class?

  1. private
  2. protected
  3. public
  4. static
  5. All the above

3 . which of the following modifiers are applied to the top level classes?

  1. static
  2. private
  3. strictfp
  4. abstract
  5. All the above

4 . which modifer is uesd to stop overridding a method?

  1. final
  2. static
  3. abstract
  4. 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:

  1. Modifiers
  2. Compiler error
  3. Exception thrown at runtime
  4. None of the above

6 . which of the following are valid syntax for a toplevel class?

  1. public static class Test6{}
  2. public abstrct class Test6{}
  3. private final class Test6{}
  4. public final class Test6{}

7 . which of the following are valid syntax for nested classes?

  1. private final abstract class Test7{}
  2. private final class Test7{}
  3. private static class Test7{}
  4. 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:

  1. new Test8.Inner().method();
  2. new Test8().Inner().method();
  3. new Test8.Inner.method();
  4. 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:

  1. new Test9.Inner().method();
  2. new Test9().Inner().method();
  3. new Test9.Inner.method();
  4. Compiler error

10 . which of the following modifiers are applied to local classes(classses inside method)?

  1. private
  2. public
  3. protected
  4. 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.

Comments

comments

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Speak Your Mind

*

Close
Please support the site
By clicking any of these buttons you help our site to get better