JavaBeat

  • Home
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Privacy
  • Contact Us

OCPJP 6 Mock Exam -19

January 22, 2014 by Krishna Srinivasan Leave a Comment

1 . What will be the output?

[code lang=”java”]
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();
}
}
[/code]

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?

[code lang=”java”]
public abstract final class Test5{
public static void main(String args[]){
System.out.println("Modifiers");
}
}
[/code]

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?

[code lang=”java”]
public class Test8{
class Inner{
public void method(){
System.out.println("Inner class");
}
}
public static void main(String args[]){
// ?
}
}
[/code]

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?

[code lang=”java”]
public class Test9{
static class Inner{
public void method(){
System.out.println("Inner class");
}
}
public static void main(String args[]){
// ?
}
}
[/code]

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.

Filed Under: Certifications Tagged With: OCPJP, OCPJP 6

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.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Follow Us

  • Facebook
  • Pinterest

As a participant in the Amazon Services LLC Associates Program, this site may earn from qualifying purchases. We may also earn commissions on purchases from other retail websites.

JavaBeat

FEATURED TUTORIALS

Answered: Using Java to Convert Int to String

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Copyright © by JavaBeat · All rights reserved