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
TCS · Object Oriented Programming
Practice Object Oriented Programming questions specifically asked in TCS interviews – ideal for online test preparation, technical rounds and final HR discussions.
Questions
9
Tagged for this company + subject
Company
TCS
View company-wise questions
Subject
Object Oriented Programming
Explore topic-wise practice
Go through each question and its explanation. Use this page for targeted revision just before your TCS Object Oriented Programming round.
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 company + subject page with full company-wise practice and subject-wise practice. You can also explore other companies and topics from the links below.
Object Oriented Programming models real-world entities as objects that contain both data and behavior. This makes programs modular, reusable, and easier to maintain compared to procedural approaches.
A class acts as a blueprint that defines structure and behavior, while an object is a concrete instance created from that blueprint. You can create multiple objects from a single class.
class Car { }
Car c1 = new Car();Inheritance allows a class (child) to reuse and extend the functionality of another class (parent). It promotes code reuse and hierarchical classification.
class Animal { void eat(){} }
class Dog extends Animal { }Method overloading allows a class to have multiple methods with the same name but different parameter lists. It improves code readability and flexibility by handling different input types or counts.
int add(int a,int b){return a+b;}
double add(double a,double b){return a+b;}The private modifier restricts access to members so they can be used only within the same class. It enforces encapsulation by preventing outside modification of internal data.
class Person { private int age; }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.
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.
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.