Java MCQ – Home
Java Basic MCQ
➤ Java Hello World MCQ
➤ Find Java Keywords
➤ Java Identifier Quiz
➤ Java Data Types Quiz
➤ If-Else MCQ in Java-1
➤ If-Else MCQ in Java-2
Object class MCQ
➤ Object Class Quiz
➤ equals() Method Quiz
➤ Hashcode Value Quiz
➤ toString() Method Quiz
➤ Clone() Method Quiz
Multithreading MCQ
➤ Define a Thread-1
➤ Define a Thread-2
➤ Get/set ThreadName
➤ Thread State MCQ
➤ Thread Priority MCQ
➤ Yield(), join() & sleep()
➤ Synchronization MCQ
➤ Interthread Comms
➤ Deadlock, Daemon
Exception Handling
➤ Exception Handling-1
➤ Exception Handling-2
➤ Exception Handling-3
➤ Java try-catch MCQ-1
➤ Java try-catch MCQ-2
➤ Java try-catch MCQ-3
➤ Nested try-catch MCQ
➤ throw Keyword MCQ
➤ finally Block MCQ-1
➤ finally Block MCQ-2
➤ throws Keyword MCQ
Generics MCQ
➤ Java Generics Quiz-1
➤ Java Generics Quiz-2
➤ Java Generics Quiz-3
Collection Framework
➤ Collections Quiz-1
➤ Collections Quiz-2
➤ ArrayList MCQ-1
➤ ArrayList MCQ-2
➤ LinkedList MCQ
➤ Vector Stack MCQ
➤ Java Cursors MCQ
➤ Java TreeSet MCQ
➤ TreeSet & Comparator
Java Object Class MCQ | Also see:- Java Hashcode Value Quiz, Java Equals() Method Quiz, Java toString() Method Quiz, Clone() Method Quiz
Q1) Which of these classes is the superclass of every class in Java?
a) Integer
b) Math
c) Object
d) Exception
View Answer
Answer:- c) ObjectEither directly or indirectly, every class in Java is the child class of java.lang.Object class.
Q2) Which of the following statement is invalid?
class Animal{}
class Tiger extends Animal{}
a) Tiger is a subclass of Animal class.
b) Tiger is a subclass of the Object class.
c) Animal is a subclass of Object class.
d) None of these.
View Answer
Answer:- d) None of these.The Animal is a subclass of java.lang.Object class and Tiger is the subclass of Animal class. Indirectly Tiger is also the subclass of java.lang.Object class.
Q3) Which of the following option is the same as the below statement?
class A{}
a) class A extends Object {}
b) class A extends java.lang.Object {}
c) Both (a) and (b)
d) None of these.
View Answer
Answer:- c) Both (a) and (b)Q4) If we want to define a method that should receive all types of values then the parameter type must be?
a) Object
b) Number
c) String
d) Something else
View Answer
Answer:- a) ObjectIf we want to define a method receives any type of object, then the parameter must be of java.lang.Object type.
Q5) Which of the following method of java.lang.Object class, we can’t override in the subclass?
a) hashCode()
b) getClass()
c) finalize()
d) clone()
View Answer
Answer:- b) getClass()The getClass() method is a final method and it can’t be overridden in the subclasses.
Q6) Which of the following method is internally not called by the Object.toString() method?
a) getClass()
b) hashCode()
c) getName()
d) finalize()
View Answer
Answer:- d) finalize()The toString() method of java.lang.Object is implemented as, return getClass().getName() + “@” + Integer.toHexString(hashCode());
Q7) Whenever we are overriding the equals() method then it is recommended to override which method of the java.lang.Object class?
a) toString()
b) hashCode()
c) clone()
d) getClass()
View Answer
Answer:- a) hashCode()Two equivalent objects should have the same hashcode. We should follows this relation between hashCode() and equals() method. Hence it is recommended to override the hashCode() method. Based on which parameter we override equals() method, it is highly recommended to use the same parameter while overriding hashCode() also.
Q8) Generally, which of the following method is overridden in the subclass just to change the accessibility modifier, not to change the implementation logic.
a) getClass()
b) clone()
c) equals()
d) hashCode()
View Answer
Answer:- b) clone()The clone() method of the Object class is protected and because of this, we can access it only in the subclass, not in the user class (like Test class). To overcome this problem we must override the clone() method of java.lang.Object class. Since we are overriding the clone() method just to change the accessibility modifier not to change the implementation logic so while overriding we must call Object class clone() as super.clone().
Q9) Find the output of the below Java program?
class Student {}
public class Test {
public static void main(String[] args) {
Student s1 = new Student();
System.out.println(s1.getClass().getName());
}
}
a) Test
b) Student
c) Object
d) Class
View Answer
Answer:- b) StudentQ10) Whenever we call the getClass() method then which of the following statement is valid.
a) Test class is loaded, stored in JVM & java.lang.Class object reference is returned. The static variable, static block, the main method of the Test class are not executed.
b) Test class is loaded, stored in JVM & java.lang.Class object reference is returned. The static variables and static blocks are executed. But the main method is not executed.
c) Already created Class object reference with the Test class is returned.
d) None of these
View Answer
Answer:- c) Already created Class object reference with Test class is returned.The getClass() method is a non-static method and it means to call getClass() method object must be there. The object can be created after class loading, and static variable/block execution.
If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!