Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SCJP Java Interview Questions part-I

In this blog, I am sharing SCJP written Test Exam Questions and answers. Those are preparing for SCJP/OCJP Examination must read these interview questions. We cover here inheritance,polymorphism,Exception Handling and Multi-threading concepts. I highly recommended  take the Core Java Course,before attempting SCJP/OCJP TEST.
1) Given 
int x=0;
int y=10;
do{
y--;
++x;
}
while(x
System.out.println(x+","+y);

then what is the result?

A. 5,6
B. 5,5
C. 6,5
D. 6,6

Answer: B

2)
Choose the correct statement:

a. "A extends B" is correct if and only if A is a class and B is an interface
b. "A extends B" is correct if and only if A is an interface and B is a class
c. " A extends B" is correct if A and B are either both classes or both interfaces
d. "A extends B" is correct for all combinations of A and B being classes or interfaces

Answer: C

3) 
public class TestString
{
public static Void main(String[] args)
{
String str="420";
str+=42;
System.out.println(str);
}
}
What is the output?

A. 42
B. 420
C. 462
D. 42042
E. Compilation Error
F. An exception is thrown at run time

ANSWER: D

4) 
public class A extends B
{
public Static Void main(String[] args)
{
short myNum=7;
System.out.println(add(myNum,6));
}
}
class B
{
int add(int x,int y)

{
return x+y;
}
what is the result?
a. 13
b. Compilation fails due to multiple errors
c. Compilation fails due to an error on line 5
d. Compilation fails due to an error on line 9

Answer: C

5) 

Choose the correct one to define enum:

a. enum A{ ONE TWO THREE}
b. enum A{ ONE TWO THREE};
c. enum A{ ONE ,TWO,THREE};
d. None of the above

Answer:C



6) 
public static void main(String [] args)
{

try{
args=null;

args[0]="test";
System.out.println(args[0]);
}
catch(Exception ex)
{
System.out.println("Exception");
}
catch(NullPointerException npe)

{
System.out.println("Nullpointerexception");
}
}

What is the Result?

A. test
B. Exception
C. Compilation fail
D. NullPointerException

Answer: C

8) 

public class Test
{
static int[]a;

static 
{
a[0]=2;
}
public static void main(String[] args)
{}
}
Which exception or error will be thrown when a programmer attempt to run this code?

A. java.lang.StackOverflowError
B. java.lang.IllegalStateException
C. java.lang.ExceptionInInitializerError
D. java.lang.ArrayIndexOutOfBoundException

Answer: C

9) 
Which can appropriately be thrown by a programmer using Java SE technology to create a Desktop application?

A. ClassCastException
B. NullPointerException
C. NoClassDefFoundError
D. NumberFormatException
E. ArrayIndexOutOfBoundException

Answer: D

10) 
try{
int x=Integer.parseInt("two");

Which could be used to create an appropriate catch block?
A. ClassCastException
B. IllegalStateException
C. NumberFormatException
D. IllegalArgumentException
E. ExceptionInInitializerError
F. ArrayIndexOutOfBoundException

Answer: C and D are correct. Integer.parseInt can throw a NumberFormatException and IllegalArgumentException is its superclass. But A,B,E and F are not in NumberFormatException's class hierarchy.

11)
Find the Correct Statement:

A. Cohesion is the OO principle most closely associated with hiding implementation details
B. Cohesion is the OO principle most closely associated with making sure that classes know about other classes only through their APIs
C. Cohesion is the OO principle most closely associated with making sure that a class is designed with a single well-focused purpose
D. Cohesion is the OO principle most closely associated with allowing a single object to be seen as having many types.

Answer:  C

12)
class Animal

{
public void eat()
{
System.out.println("Animal eating");
}
class Dog extends Animal
{
public void sniff();
System.out.println("Dog sniffing");
public void eat()
System.out.println("Dog eating");
}
}
public class Test
{
public static void main(String[] args)
{
new Test().run();
}
void run()

{
new Dog().eat();
((Animal)new Dog()).eat();
((Animal)new Dog()).sniff();
}
}

What is Result?

A. Animal eating Dog sniffing
B. Dog eating Dog sniffing
C. Error in Compilation at line 15
D. Error in Compilation at line 16

Answer: D

13) 
class A{
}
class B extends A
{}
public class Test
{
static String s="-";

public static void main(String[] args)
{
A[]aa=new A[2];

B[]bb=new B[2];
add(aa);
add(bb);
add(5);
System.out.println(s);
}
static void add(A[]...a2)

{
s+="4";
static void add(B[]...b1)
{
s+="3";
}
static void add(B[]b1)
{
s+="2";
}
static void add(Object o)
{
s+="1";
}
what is the Result?

A. compilation fails
B. -431
C. -421
D. -121

Answer: D

14) 

class Test
{
int[] cls={1,2,3,4,5,6,7,8,9,10};

}
public class College

{
public static void main(String[] args)

{
College[] c=new College[3];
c[0]=new College();
College co=new College();
c[1]=co;
co=null;
c[1]=null;
//TO DO
}
}
How many Objects will be created and after reaching at line 13,how many object will be eligible for GC

A. 5 created and 2 for GC
B. 3 created and 1 for GC
C. 3 created and 2 for GC
D. None

Answer: A

15) 

Choose the correct way to create a thread class:

A. public class MyThread extends Runnable
    {
      public  void run(){
     }}
B. public class MyThread extends Object
    {
      public  void run(){
     }}

C. public class MyThread implements Runnable
    {
      public  void run(){
     }}
D. public class MyThread extends Runnable
    {
       void run(){
     }}

Answer: C


This post first appeared on Learnprogramingbyluckysir, please read the originial post: here

Share the post

SCJP Java Interview Questions part-I

×

Subscribe to Learnprogramingbyluckysir

Get updates delivered right to your inbox!

Thank you for your subscription

×