Java quiz


This section contains 14 MCQ quizlets on core Java programming. It comprises questions that are similar to the questions that can be expected on the real certification exam. Going through this exam will give you a good indication of how well you are prepared for the real exam or whether any topic requires further study.



Mock test For Certification in JAVA Programming

The test consists of 14 questions on Java.

No negative marking for this test.

No Time limit

The pass percentage is 70%

The correct answer with a description will be displayed after the answer has been marked.

Submit the test to calculate your score once you are done with all the questions.

Complexity Level- Moderate







Q1. Given the following class, which statement CANNOT be inserted at position 1

class abcd{

int a;
int b=0;
static int c;

public void m() {
int d;
int e=0;
//position 1
}
}
















Q2: What is wrong with the following code?

class abcd extends Exception{}

public class pqrs{

public void func1() {
try {
func2();
}
finally {
func3();
}
catch(abcd exp) {
}
}

public void func2() throws abcd{
throw new abcd();
}

public void func3() throws RuntimeException{
throw new RuntimeException();
}
}
















Q3. What will be written to the standard output when the following program is run?

class testClass{

public static void main(String[] args) {
String str ="restructure";
System.out.println(str.substring(2, 3));
}
}

















Q4: Which statements are true about the effect of the >> and >>> operators?

Select all that applies:























Q5: Which declarations of the main() method are valid in order to start the execution of an application?

Select all that applies:























Q6. What will be the output when the following program is run?

class testClass{

public static void main(String[] args) {
for(int i=12;i>0;i-=3)
System.out.println(i);
System.out.println("");
}

}














Q7: What will be the result of attempting to compile and run the following code?

class testClass{

static int a;
int b;

public testClass() {
int c;
c=a;
a++;
b+=c;
System.out.println("c="+c +"a="+a +"b="+b);
}

public static void main(String[] args) {
new testClass();
}
}

Select the correct answer:














Q8. Which declarations of a native method are valid in the declaration of the following class?

class testClass{

// insert declaration of a native method here

}

Select All that applies:




















Q9: Which collection implementation is suitable for maintaining an ordered sequence of object, when objects are frequently inserted and removed from the middle of the sequence?

Select the correct answer:



















Q10: Which statements can be inserted at the indicated position in the following code to make the program print 1 on the console output when executed?

class testClass{

int a=1;
int b=1;
int c=1;

class innerClassTest{

int a=2;
int get() {
int c=3;

// insert statement here
return c;

}
}
testClass(){

innerClassTest i = new innerClassTest();
System.out.println(i.get());
}

public static void main(String[] args) {
new testClass();
}

}



















Q11. Select the correct method declaration that enforces the below given condition-

A method within a class is only accessible by classes that are defined within the same package as the class of the method.


















Q12. Given two collection objects referenced by obj1 and obj2, which statements are true?


















Q13. Select All the valid statements about the following code:

class testClass{

public testClass() {
}

public testClass(int i) {
this();
}
}

class testClass2 extends testClass{

public boolean testClass2(String msg) {

return false;
}
}

class testClass3 extends testClass2{

private testClass3() {
super();
}

public testClass3(String msg) {
this();
}

public testClass3(int i) {
}
}





















Q14. Select the valid statements about casting and conversion: