1. What is Abstraction?
Definition : Abstraction means representing only essential features by hiding all the implementation details. In object
oriented programming languages like C++, or Java class is an entity used for data abstraction purpose.
Or
In object-oriented programming, an Abstract Data Type (ADT) is a mathematical model that defines a set of data and a set
of operations on that data. It focuses on what the data represents and what can be done with it, rather than how the data is
stored or manipulated internally.
Key Characteristics of ADTs:
• Abstraction: Hides the internal implementation details, providing a clear separation between the
interface and implementation.
• Specification: Defines the operations that can be performed on the data, including their parameters and
return types.
• Implementation: The concrete representation of the ADT, which can vary without affecting the overall
behaviour.
Example
class Student {
public int roll;
char name[ 10 ];
public:
void input ( );
void display ( );
In main function we can access the functionalities using object. For instance
Student obj;
obj.input ( );
obj.display ( );
Thus only abstract representation can be presented, using class.
2. Define state, data member, attribute, property
a. State
• Definition: The state of an object represents the current values of its attributes or data members at a given point in
time.
• Example: For a Car object, the state might be:
color = "red", speed = 60, engineOn = true
b. Data Member
• Definition: A data member is a variable that belongs to a class and holds data specific to each object (if instance
member) or shared across all objects (if static/class member).
• Example: In a Student class, name, rollNo, and marks can be data members.
c. Attribute
• Definition: An attribute is essentially another term for a data member. In object-oriented terminology, especially in
UML and high-level modeling, it refers to the characteristics of a class.
• Note: The terms attribute and data member are often used interchangeably.
• Example: In a class Book, attributes might include title, author, and ISBN.
d. Property
• Definition: A property is a higher-level abstraction that provides access to private data members using getters and
setters. It allows controlled access and encapsulation.
3. What is data hiding?
Data hiding, also known as information hiding, is a core concept in object-oriented programming (OOP) that restricts direct
access to an object's internal data and methods. It involves encapsulating data within a class and exposing it only through
controlled interfaces (methods or functions), thus enhancing security, maintainability, and code organization
4. What is Encapsulation?
• Encapsulation means binding of data and method together in a single entity called class.
• The data inside that class is accessible by the function in the same class. It is normally not accessible
from the outside of the component.
5. Explain differences between Abstraction and Encapsulation.
Abstraction = "Don't show unnecessary details."
Encapsulation = "Don't allow direct access to data
Abstraction Encapsulation
Hides implementation details and shows only Wraps data (variables) and code (methods) into a
essential features of an object. single unit (class), and restricts direct access to some
of the object’s components.
Focuses on what an object does. It is independent To protect data from unauthorized access. It is depends
upon object data type. upon object data type.
Achieved using abstract classes, interfaces. Achieved using access modifiers (private, protected,
public) of class
It is used in software design phase. It is used in software implementation phase.
6. What is Message Passing?
In object-oriented programming (OOP), message passing is the process of objects communicating with each other by sending
requests (messages) to perform specific actions or access data. This interaction allows objects to collaborate and build complex
systems, with each object responsible for its own data and behavior. It's a core concept that enables encapsulation, modularity.
When one object needs another object to do something, it sends a message. This message typically includes:
• The target object (the object receiving the message).
• The method (function) to be executed on the target object.
• Any necessary data (arguments) for the method
7. Differentiate Generalization and Specialization with example.
Generalization is the process of defining a more general class (superclass) from more specific classes (subclasses), while
Specialization is the reverse, creating more specific classes from a general one. Generalization is a bottom-up approach,
while specialization is top-down. For example ‘Vehicle’ class is a generalised class from which ‘Car’,’Truck’,’Motor
Cycle’ classes are inherited as a specialized class.
8. What is aggregation ?
In Object-Oriented Programming (OOP), aggregation is a "has-a" relationship between classes, where one class contains
or is composed of one or more objects of another class. It represents a weaker form of association, where the contained
objects can exist independently of the containing object.
9. Explain Degree of an Association with example. Explain Cardinality Ralations of Associations with example.
The degree of an association refers to the number of objects of one class that can be related to objects of another class. It
defines the multiplicity of the relationship, indicating how many objects are associated at most. Common degrees include
one-to-one, one-to-many, many-to-one, and many-to-many.
Cardinality in object-oriented programming (OOP) defines the numerical relationship between objects in an association. It
specifies how many instances of one object can be associated with instances of another object. The four main types of
cardinality are one-to-one, one-to-many, many-to-one, and many-to-many.
10. What is association?
In Object-Oriented Programming (OOP), association represents a relationship between two or more classes where objects
of one class are connected to objects of another class. It signifies a "has-a" relationship, indicating that one object uses or
is related to another object. This connection allows objects to collaborate and interact with each other to achieve specific
tasks or functionalities. Associations can represent different relationships like one-to-one, one-to-many, many-to-one, or
many-to-many.
11. What is composition?
Composition is a type of association that represents a strong "has-a" relationship between two classes, where: One class
owns another class, and the owned object cannot exist independently of the owner.
12. What is Object ?
• Object is an instance of a class.
• When object is create it will occupy the Heap memory.
• Objects are basic run-time entities in object oriented programming.
• Using objects we can access the member variable and member function of a class.
• Object is create with new keyword and calling the class constructor.
• For example - If the class is Country then the objects can be India, China, Japan and so on.
• A single class can create any number of objects.
Declaring objects - The syntax for declaring object is - Class_Name =new Class_Name();
Example Fruit f1=new Fruit();
For the above example Fruit is a class and f1 is the object. The keyword new will allocate the memory.
13. What is Class ?
• A blueprint or template that defines the properties (attributes) and behaviors (methods) of objects. It is a
collection of objects of similar type.
• Logical entity (does not occupy memory until an object is created)
• The concept of class is similar to the concept of structure in C.
• Class is created with ‘class’ keyword.
Example :
class Rectangle
{
private int l,b;
public void getdata ( );
public void area( );
public void print_data ( );
}
14. Explain the difference between Class and Object.
Class Object
A blueprint or template that defines the A real-world entity or instance created from a
properties (attributes) and behaviors (methods) class.
of objects
Logical entity (does not occupy memory until an Physical entity (occupies memory when created).
object is created
Defined once, using the class keyword. • Created from a class using the new
keyword in languages like Java.
15. What is object oriented programming? How is it different from the procedure oriented programming?
Object-oriented programming (OOP) is a computer programming model that organizes software design around data, or
objects, rather than functions and logic. An object can be defined as a data field that has unique attributes and behavior.
Difference: OOP deals with objects rather than functions, follows bottom-up approach, has access specifiers, adding new
data and function is easy, more secured. It has also the concept of inheritance, constructor, overloading, overriding. In a
procedural programming focuses on function that process data. It is less secure that OOPs and divide the large program in
functions.
16. What are the advantages and disadvantages of OOP?
Object-Oriented Programming (OOP) is a popular programming paradigm based on the concept of "objects", which
encapsulate data and behaviour.
Advantages of OOP
a. Modularity - Code is organized into classes and objects,
b. Reusability -Through inheritance, existing code can be reused in new classes.
c. Encapsulation -Data and methods are bundled together.
• Access specifiers (private, public, protected) prevent unauthorized access, improving security and data
hiding.
d. Polymorphism
• Allows one interface, many implementations.
• Enables flexible and dynamic method binding (overloading and overriding).
e. Abstraction
• Hides complex implementation details.
• Only essential features are exposed, simplifying interface usage.
f. Easier Maintenance and Debugging
• Changes in one class don't affect others if properly encapsulated.
• Classes are independent units, making bugs easier to find and fix.
g. Improved Collaboration - Suitable for team-based development.
Disadvantages of OOP
• Increased Complexity
• Slower Execution
• Size Overhead
• Not for all problem
12. Difference between JVM and JRE
JVM : The JVM (Java Virtual Machine) is a virtual machine that enables Java programs to run on any device or operating
system. It provides an environment in which Java bytecode can be executed. Java is platform independent but JVM is
platform specific. A different JVM is required for different operating systems and hardware architectures Its main function
is to load, verify, and execute Java bytecode.
JRE : The JRE(Java Runtime Environment) is a package that includes the JVM along with the necessary libraries and
components required to run Java applications. It is used to provide the runtime environment.
13. Explain java.util,Objects class java.
The java.util.Objects class, introduced in Java 7, provides a collection of static utility methods for operating on objects. Its
primary purpose is to simplify common tasks and enhance code robustness
----------------------------------------------------------------------------------------------------------------------------- -----------------
NOTE
How to Implement an ADT
• To implement an ADT, we need to choose a concrete data structure that can store the values and support the
operations of the ADT.
• We also need to write the code for each operation, using the chosen data structure and algorithms.
• The implementation details are hidden from the user by using encapsulation and abstraction techniques.
• For example, we can implement a List ADT using a dynamic array or a linked list as the concrete data structure, and
write the code for operations such as get, insert, remove, replace, size, isEmpty, isFull etc.
• The user of the List ADT does not need to know whether it is implemented using an array or a linked list, only how to
use the operations.
Concrete state space
The concrete state space of an ADT is the set of all possible values that the data can take on. The concrete state space is
implementation-dependent, meaning that it depends on how the ADT is implemented.
Concrete invariant
The concrete invariant of an ADT is a property that must be true for all valid states of the data. The concrete invariant is also
implementation-dependent.
Concrete State Space, Concrete Invariant, Abstraction Function
• A concrete state space is the set of all possible states that the concrete data structure can have .
• A concrete invariant is a property that holds for all states in the concrete state space .
• An abstraction function is a mapping from the concrete state space to the abstract state space, which preserves the
essential features of the ADT .
• For example, if we implement a Stack ADT using an array-based stack, then:
o The concrete state space is the set of all possible arrays of a fixed size that can store elements of a given
type.
o The concrete invariant is that there is an integer variable top that indicates the index of the top element in
the stack, and 0 <= top < size, where size is the capacity of the array.
o The abstraction function is a mapping from an array-based stack to a sequence of elements that represents
the contents of the stack from top to bottom.
Implementing Operations, Illustrated by the Text Example
• To implement an operation of an ADT, we need to write a function or method that takes some input parameters and
returns some output values or modifies the state of the ADT .
• The function or method should follow the specification of the operation given by the ADT, and maintain the concrete
invariant and abstraction function.
• For example, if we implement a Text ADT using a string as the concrete data structure, then:
• The concrete state space is the set of all possible strings that can store characters.
• The concrete invariant is that there is no limit on the length of the string.
• The abstraction function is a mapping from a string to a sequence of characters that represents the contents of the
text.
• To implement an operation such as insert(pos,c), which inserts a character c at position pos in the text, we can write
a function like this (in pseudocode):