• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • 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)
  • 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)

OCPJP 6 Mock Exam – 4

January 14, 2014 //  by Krishna Srinivasan//  Leave a Comment

Q 1 : What will be the output?

public class Test1{
    static void method(Object obj){
        System.out.println("Object");
    }
    static void method(String str){
        System.out.println("String");
    }
    public static void main(String args[]){
        method(null);
    }
}

Choose the one below:

  1. String
  2. Object
  3. null
  4. Compiler Error

Q 2 : What will be the output?

public class Test2{
    static void method(StringBuffer obj){
        System.out.println("StringBuffer");
    }
    static void method(String str){
        System.out.println("String");
    }
    public static void main(String args[]){
        method(null);
    }
}

Choose the one below:

  1. String
  2. Object
  3. null
  4. Compiler Error

Q 3 : What will be the output?

class Test{}
public class Test3{
   static void method(Object obj){
       System.out.println("StringBuffer");
   }
   static void method(String str){
       System.out.println("String");
   }
   static void method(Test t){
       System.out.println("Test");
   }
   public static void main(String args[]){
       method(null);
   }
}

Choose the one below:

  1. String
  2. Object
  3. Test
  4. Compiler Error

Q 4 : What will be the output?

public class Test4{
    public static void main(String args[]){
        I i1 = new A();
        I i2 = new B();
        A a = new A();
        System.out.println(i1 instanceof I);
        System.out.println(i2 instanceof B);
        System.out.println(a instanceof I);
    }
}
interface I{}
class A implements I{}
class B implements I{}

Choose the one below:

  1. true true true
  2. true false true
  3. true false false
  4. Compiler Error

Q 5 : What will be the output?

public class Test5{
    public static void main(String args[]){
        System.out.println(I.k);
    }
}
interface I{
    int k;
}

Choose the one below:

  1. 0
  2. 1
  3. null
  4. Compiler Error

Q 6 : What will be the output?

public class Test6 implements I{
    int k = 1;
    public static void main(String args[]){
        System.out.println(k);
    }
}
interface I{
    int k = 0;
}

Choose the one below:

  1. 0
  2. 1
  3. null
  4. Compiler Error

Q 7 : What will be the output?

public class Test7 implements I{
    int k = 1;
    static{
        k = k * 2;
    }
    {
        k = k * 2;
    }
    public static void main(String args[]){
        Test7 t1 = new Test7();
        Test7 t2 = new Test7();
        System.out.println(t1.k);
        System.out.println(t2.k);
        System.out.println(k);
    }
}

Choose the one below:

  1. 0
  2. 1
  3. null
  4. Compiler Error

Q 8 : What will be the output?

public class Test8{
    static int k = 1;
    static{
       k = k * 2;
    }
    {
       k = k * 2;
    }
    public static void main(String args[]){
       System.out.println(k);
    }
}

Choose the one below:

  1. 1
  2. 2
  3. 4
  4. Compiler Error

Q 9 : What will be the output?

public class Test9{
    static int k = 1;
    {
        k = k * 2;
    }
    public static void main(String args[]){
        System.out.println(k);
    }
}

Choose the one below:

  1. 1
  2. 2
  3. 4
  4. Compiler Error

Q 10 : What will be the output?

public class Test10{
    final static int k;
    static{
        k = 0;
    }
    public static void main(String args[]){
        System.out.println(k);
    }
}

Choose the one below:

  1. 0
  2. 1
  3. null
  4. Compiler Error

Answers

Q 1 : 1 is correct. String.

Q 2 : 4 is correct. Compiler Error.

Q 3 : 4 is correct. Compiler Error.

Q 4 : 1 is correct. true true true.

Q 5 : 4 is correct. Compile time error.

Q 6 : 4 is correct. Compiler Error.

Q 7 : 4 is correct. Compiler Error.

Q 8 : 2 is correct. 2.

Q 9 : 1 is correct. 1.

Q 10 : 1 is correct. 0.

Category: CertificationsTag: 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.

Previous Post: « JUDCon2014 In Bangalore, India (January 30-31, 2014 )
Next Post: OCPJP 6 Mock Exam – 5 »

Reader Interactions

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.

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

EJB 3.0 Timer Services

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact