1. What is a class in object-oriented programming?
A class defines the attributes (data) and behaviors (methods) that its object instances will have. Think of it like a blueprint for constructing many similar objects.
Get the Preplance app for a seamless learning experience. Practice offline, get daily streaks, and stay ahead with real-time interview updates.
Get it on
Google Play
4.9/5 Rating on Store
Object Oriented Programming · Question Set
Classes, Objects & Constructors interview questions for placements and exams.
Questions
14
Included in this set
Subject
Object Oriented Programming
Explore more sets
Difficulty
Mixed
Level of this set
Go through each question and its explanation. Use this set as a focused practice pack for Object Oriented Programming.
A class defines the attributes (data) and behaviors (methods) that its object instances will have. Think of it like a blueprint for constructing many similar objects.
For complete preparation, combine this set with full subject-wise practice for Object Oriented Programming. You can also explore other subjects and sets from the links below.
In Java you use the new keyword with a constructor call to instantiate an object: new Car(). Then you can assign it to a reference of type Car.
A copy constructor in C++ constructs a new object by copying values from an existing object. It’s used for object duplication and deep or shallow copy semantics.
If you don’t define any constructor in many languages (for example Java or C++), the compiler supplies a default no-argument constructor. It allows object creation without supplying parameters.
A parameterized constructor allows passing values at the time of object creation, so the object can be initialized with different states immediately.
Static members belong to the class itself and are shared across all objects; instance members are part of each object’s state and vary from object to object.
A destructor is called automatically when an object goes out of scope or is delete-ed. It allows cleanup of memory, file handles, or other resources.
In Java the == operator checks if two references refer to the same object in memory, not if they are logically equal. equals() checks content equality if overridden.
Constructor visibility determines from where an object can be created. A public constructor allows object creation from anywhere; a private constructor prevents external code from using it (useful in singletons). Protected or package-private allows controlled access. In interviews you might discuss design patterns like Singleton where private constructors are essential.
A default constructor takes no arguments; it either is provided implicitly or defined explicitly. A parameterised constructor takes one or more parameters for initialization. Example in Java: class Person { Person() { } Person(String name) { this.name=name; } } The difference influences how objects are created and initialised.
A shallow copy duplicates the object but shares references of internal mutable objects; modifications in one reflect in the other. A deep copy duplicates the object and its entire internal structure so changes in one don’t affect the other. In C++ copy constructor or clone methods handle copying; in Java you might implement Cloneable or use serialization. Explaining pitfalls and when each is needed shows depth.
In inheritance the derived class constructor implicitly or explicitly calls its base class constructor before executing its body. This ensures base class state is properly initialised. In Java you use super(); in C++ you can specify initialiser list. Constructor chaining avoids duplicate code and handles complex object initialisation reliably.
Constructor chaining means one constructor calls another in the same class (or base class) to reuse initialization logic. It helps avoid duplication and maintain consistent object setup.
When code uses new to create an object memory is allocated, the constructor (default or parameterised) initialises the object, and the object is ready for use. Later when it is no longer referenced (in languages with GC) or delete-ed (in C++), destructor or GC finaliser runs to free resources. Understanding this helps you reason about memory management and resource leaks in interviews.