Java Important MCQ question and answer

Java important mcq question with an answer.


1)Which of the following is not keyword in java ? 
a)null 
b)import 
c)volatile 
d)package 

2)What is the full form of JDK ?
 a)Java Data Kit 
b)Java Definition Kit 
c)Java Development Kit 
d)Java Design Kit 

3)Which command is used to compile a java program ?
 a)Java 
b)Javac 
c)Jdk 
d)Jar 

4)What is the full form of JVM? 
a)Java Variable Machine 
b)Java Virtual Machine 
c)Java Variable Mechanism 
d)Java Virtual Machenism 

5)The expected signature of the main method is public static void main(). What happens if we make a mistake and forget to put the static keyword ? 
a)The JVM issues an error saying that main method should be declared static 
b)The JVM successfully invokes the main method
c)The JVM fails at runtime with NoSuchMethodError
d)The JVM successfully invokes the main method 

6)Which of the following is generated when the source code is successfully compiled ?
a)Output 
b)Error 
c)Bytecode 
d)None of above 

7)The extension name of a Java source code file is ?
a).java 
b).class 
c).obj 
d).exe 

8)In Java arrays are 
a)Objects 
b)Object References 
c)Primitive data type 
d)None of the above 

9)Which one of the following is a valid statement? 
a)char[] c = new char(); 
b)char[] c = new char[5]; 
c)char[] c = new char(4); 
d)char[] c = new char[]; 





10)Size of int in Java is 
a)16 bit 
b)20 bit 
c)32 bit 
d)64 bit 

11) What is the output? 
class A{        
public static void main(String args[]){                
int x;                
x = 10;               
 if(x == 10){                        
int y = 20;                       
 System.out.print("x and y: "+ x + " " + y);                        
y = x*2;                
}                
y = 100;                
System.out.print("x and y: " + x + " " + y);        

}
a)10 20 10 100 
b)10 20 10 20 
c)10 20 10 10 
d)Error 

12) What will be the output? 
public class Test {        
static void test(float x){                
System.out.print("float");        
}
static void test(double x){                
System.out.print("double");        
}
public static void main(String[] args){                
test(99.9);        

}
a)float 
b)double 
c)Compilation Error 
d)None of the above 

13)A java class can have more than one constructor?
a)Yes 
b)No 

14)If we don’t write any default constructor, then 
a)Java will incorporate a default constructor 
b)Compilation error 
c)Run Time Error 
d)None of the above 

15) In java Constructor can be overloaded 
a)Yes 
b)No 

16)The Inheritance keyword is 
a)implement 
b)extend 
c)extends 
d)None of the above 

17)What will be the return type of a method that not returns any value? 
a)int 
b)void 
c)double 
d)None of the above 

18)In which area of memory, the system stores parameters and local variables whenever a method is invoked? 
a)Stack 
b)Heap 
c)Array 
d)None of the above 

19)Which of the modifier can't be used for constructors?
a)public 
b)private 
c)static 
d)protected

20)The variables declared in a class for the use of all methods of the class are called 
a)Reference variable 
b)object 
c)Instance variable 
d)None of the above.

21)The implicit return type of a constructor is 
a)void 
b)A class object in which it is defined. 
c)double 
d)None of the above 

22)The main method should be static for the reason 
a)It can be accessed easily by the class loader 
b)It can be accessed by every method or variable without any hindrance. 
c)It can be executing without creating any instance of the class 
d)None of the above. 

23)What is the default constructor of the class public class Test { }
a)public Test(void) 
b)public void Test() 
c)Test() 
d)public Test() 

24)Which is true? 
a)"X extends Y" is correct if and only if X is a class and Y is an interface. 
b)"X extends Y" is correct if and only if X is a interface and Y is a class. 
c)"X extends Y" is correct if X and Y are either both classes or both interface. 
d)"X extends Y" is correct for all combinations of X and Y being classes and/or interfaces. 

25)Which is not a valid statement based on given code? 
a)A a = new A(); 
b)B a = new B(); 
c)A a = new B(); 
d)B b = new B(); 

26)A class can extend 
a)A single Class 
b)Multiple Classes
c)Exactly two classes 
d)None of the above. 

27)An Interface can have 
a) Abstract Functions 
b)Functions 
c)Variables 
d)All the above 

28) we can not instantiate 
a)a class 
b)an Interface 
c)an abstract class and an interface 
d) a class and an abstract class 

29)Which of the following tool used to execute java code. 
a)javac 
b)applet 
c)java 
d)rmic 

30)Single line comment starts with _________ in Java. 
a)// 
b)/** 
c)/*  
d)None of the above

Post a Comment

0 Comments