Learn JAVA MCQs
Prepare JAVA MCQs (Multiple choice Questions) for exam and job interviews.
Which of the following is not a Java keyword?
1) volatile
2) interface
3) extends
4) pointer
Answer : pointer
Which method is used to get the length of an array in Java?
1) size()
2) length()
3) length[]
4) None of the above
Answer : length()
Which of these cannot be used for a variable name in Java?
1) identifier
2) keyword
3) class
4) variable
Answer : keyword
Which of the following is a marker interface in Java?
1) Runnable
2) Serializable
3) Cloneable
4) All of the above
Answer : Serializable
What is the default value of a boolean variable in Java?
1) true
2) false
3) 0
4) null
Answer : false
What is the size of an int in Java?
1) 16 bits
2) 32 bits
3) 64 bits
4) Depends on the system
Answer : 32 bits
What is the correct syntax to declare a package in Java?
1) package myPackage;
2) Package myPackage;
3) import myPackage;
4) None of the above
Answer : package myPackage;
Which of the following is a valid constructor for the class MyClass?
1) MyClass() {}
2) void MyClass() {}
3) MyClass(void) {}
4) None of the above
Answer : MyClass() {}
Which method is called when an object is garbage collected?
1) finalize()
2) dispose()
3) destroy()
4) clean()
Answer : finalize()
Which of the following is true about inheritance in Java?
1) A class can extend multiple classes.
2) A class can implement multiple interfaces.
3) Both 1 and 2
4) None of the above
Answer : A class can implement multiple interfaces.