Java Objects and Classes MCQ Questions with Answers

Practice Java Objects and Classes MCQ questions with answers and explanations. This free Java quiz is designed for beginners, college students, job seekers, and software developers preparing for interviews, placements, and OCJP certification exams.

The quiz covers important Java concepts such as classes, objects, constructors, methods, instance variables, object creation, memory allocation, and object-oriented programming fundamentals. Attempt the questions below to evaluate your understanding of Java programming and identify areas for improvement.

What are Objects and Classes in Java?

Objects and Classes are the fundamental building blocks of Object-Oriented Programming (OOP) in Java. A class is a blueprint or template that defines the properties (variables) and behaviors (methods) of an object. It specifies what data an object can store and what actions it can perform.

An object is an instance of a class. When a class is created, no memory is allocated until an object of that class is instantiated. Each object has its own state and behavior based on the class definition. For example, if Student is a class, then Rahul, Priya, and Amit can be considered different objects of that class.

Java uses classes and objects to model real-world entities and solve complex programming problems efficiently. A strong understanding of objects and classes is essential for learning advanced Java concepts such as inheritance, polymorphism, encapsulation, and abstraction.

Key Concepts of Java Objects and Classes

Class

A class is a user-defined blueprint that defines the structure and behavior of objects.

Object

An object is an instance of a class that contains actual values and can access the methods defined in the class.

Constructor

A constructor is a special method that is automatically invoked when an object is created and is used to initialize object data.

Methods

Methods define the actions or behaviors that an object can perform. They contain the business logic of a program.

Instance Variables

Instance variables store the state of an object. Each object maintains its own copy of these variables.

Encapsulation

Encapsulation is the process of binding data and methods together within a class while restricting direct access to sensitive information.



Java Online Quiz

Topic- Objects and Classes in Java

The test consists of 14 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 the correct output for the below code snippet:

public class abc {
int i;
public int a(int x){
i=x+1;
System.out.println("Value of i="+i);
return i;
}
}

public class xyz {
abc obj1,obj2;

public xyz(){
obj1=new abc();
obj2=obj1;
obj2.a(3);
}
public static void main(String[] args) {
xyz x=new xyz();
}
}













Q2: A reference variable in Java is _________

Select the correct answer:













Q3: An instance variable in Java is _______














Q4: A static variable in Java is _______














Q5: Select all that applies for a nested static member class:





















Q6: An anonymous class in Java is _____?

Select the correct answer:













Q7: Garbage collection in Java is _____













Q8: Object Finalization in Java is __________














Q9: A final class in java is _______

Select the correct answer:














Q 10: An abstract class cannot be instantiated:

Select True or False:











Q 11: System.gc() is a method used to _______











Q 12: Select all that applies for a nested Non-static member class:






















Q 13: An object in java can be referenced by multiple reference variables:

Select True or False












Q 14: A local class in java is ________