Java MCQ Questions and Answers on Data types and variables


Java multiple choice questions for OCJP preparation. Free online self-assessment test on Java programming language to evaluate the understanding of Java basics for beginners. First test from the Java online test series. These mock test series on Java programming language consisting of a wide range of multiple-choice questions are designed to evaluate the self-performance of Java skills. Very useful in interviews and OCJP certification exam preparation.



Java Online Mock OCJP Test Series: 2

Topic- Data types and variables in Java

The test consists of 15 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- Easy





Q1: Select all the primitive data types in java






























Q2: An identifier in java is ________

Select the correct answer:











Q3: Which of the following is not a keyword in java ______













Q4: Which of the following is Not an Integer data type?















Q5: Which of the following are floating-point data types?

















Q6: Object class in java is ____?













Q7: Select the correct statement for the lifetime of an instance variable ____












Q8: What is the output of the below program:

public class finalTest {
final static int r=9;
public static void main(String[] args) {
r++;
System.out.println(r);
}
}













Q9: Select the correct console output of the below program:

public class finalTest {
finalTest func1() {
System.out.println("This is func1");
return new finalTest();
}
String func2() {
return "returning string2";
}

public static void main(String[] args) {
finalTest obj2;
obj2=new finalTest();
System.out.println(obj2.func1().func2());
}
}













Q 10: Which one of the below statements is true for a final method:










Q 11: Select the correct console output for the below program:

class test123 {
test123(){
System.out.println("Constructor Superclass");
}
}

public class finalTest extends test123{
finalTest(){
System.out.println("Constructor sub class");
}
public static void main(String[] args) {
finalTest obj2=new finalTest();
}
}












Q 12: A local variable (belonging to a method, as shown below) must be initialized in the method before it is being used. True or False?

public void func2() {
int var1;
var1=5;
System.out.println(var1);
}









Q 13: An instance or static variable, if not initialized explicitly, then?

Select the correct statement:










Q 14: Select the correct output of the below program:

public class finalTest {
int var1;
public void func2() {
System.out.println(var1);
}
public static void main(String[] args) {
finalTest obj2=new finalTest();
obj2.func2();
}
}













Q 15: Which of the following is not a valid assignment:

1: char c='a';
2: short s=20;
3: long l=021;
4: int var2=(int)true;
5: float f=-123;
6: double d=0x12345678;
7: int var1=c;

























Quantitative aptitude - practice tests


A series of aptitude practice tests comprising multiple-choice questions (MCQ) on varied aptitude topics that evaluate the quantitative ability.