Java MCQs - Unit II: Classes, Objects, and Methods
Section 1: Classes, Objects, and Variables
1. Which of the following is a correct definition of a class in Java?
a) A data type
b) A template for objects
c) A memory block
d) A Java library
2. Which of these is used to create an object in Java?
a) malloc()
b) create()
c) new
d) alloc()
3. What is the correct syntax to create an object of Student class?
a) Student s = Student();
b) Student s = new Student();
c) new Student s = Student();
d) object Student = new Student();
4. Instance variables are:
a) Declared inside methods
b) Shared among all instances
c) Declared in a class but outside methods
d) Always static
5. Which of the following is NOT a valid variable type in Java?
a) local
b) global
c) instance
d) static
Java MCQs - Unit II: Classes, Objects, and Methods
6. What is true about an object in Java?
a) It is a class
b) It is always a String
c) It has state and behavior
d) It cannot be created at runtime
7. What keyword is used to refer to the current object in Java?
a) self
b) this
c) super
d) that
8. Which of the following is NOT a feature of the object class in Java?
a) clone()
b) finalize()
c) equals()
d) compile()
9. What is a container that holds a value during execution called?
a) Method
b) Object
c) Variable
d) Class
10. Which of these classes is NOT a predefined Java class?
a) Object
b) Math
c) System
d) Student