What are object oriented concepts? What is difference between object-based, object-oriented and fully object-oriented language?
Object-oriented concepts include encapsulation, abstraction, inheritance, and polymorphism.
Object-based languages support objects but lack inheritance and polymorphism (e.g., JavaScript pre-ES6).
Object-oriented languages support objects, classes, and inheritance (e.g., C++, early Java).
Fully object-oriented languages treat everything as objects, including primitive types (e.g., Smalltalk, Ruby).
What are advantages of Object-Oriented Programming? What is data security?
Advantages of OOP:
Data security in OOP refers to protecting data through encapsulation by making fields private and only accessible through controlled methods.
What is class and object? Give real-life example.
A class is a blueprint/template that defines properties and behaviors.
An object is an instance of a class with specific values for its properties.
Real-life example: Car (class) vs. a specific Toyota Camry with VIN 1234 (object).
What are characteristics of object? Explain them.
What is the need of getter and setter functions in class?
Getters and setters:
What is abstraction and encapsulation. Give real-life example.
Abstraction: Exposing essential features while hiding complexity. Example: Car dashboard (exposes speed, fuel without engine complexity)
Encapsulation: Bundling data and methods, restricting direct access to data. Example: Medicine capsule (contents packaged and accessed only by intended means)
What is polymorphism? What are its types? Explain them with examples.
Polymorphism: Ability of objects to take multiple forms.
Types:
add(int, int)
and add(double, double)
Animal.makeSound()
overridden by Dog.makeSound()
What is method overloading? Which are the rules of method overloading? Why return type is not considered in method overloading?
Method overloading: Multiple methods with same name but different parameters.
Rules:
Return type isn't considered because the compiler identifies methods by signature (name and parameters) during method calling. Return types alone don't provide enough information at the call site.
What are different types of hierarchy? When to use which one?
What is the difference between method overloading and method overriding?
Overloading:
Overriding:
What is object slicing? Explain object slicing in context of up-casting?
Object slicing occurs when a derived class object is assigned to a base class object, causing loss of derived class-specific members.
In upcasting, a derived class reference is converted to a base class reference. If done through object assignment rather than reference, slicing occurs.
What is down-casting and when it is required? Explain with code.
Downcasting is casting a base class reference to a derived class reference.
Required when:
Animal animal = new Dog(); // Upcasting
// animal.bark(); // Error - Animal doesn't have bark()
Dog dog = (Dog)animal; // Downcasting
dog.bark(); // Now works
What do you know about association, composition and aggregation? Explain with the help of example.
Association: Relationship between objects Example: Teacher and Student (have relationship but independent lifecycle)
Aggregation: "has-a" relationship, weak ownership Example: Department and Professors (department has professors, but they exist independently)
Composition: "part-of" relationship, strong ownership Example: House and Rooms (rooms cannot exist without house)
What are different types of inheritance? Explain with the help of example. What are problems with multiple inheritance?
Types:
Problems with multiple inheritance:
What is difference between interface, abstract class and non-abstract class? Which one to use where?
Interface:
Abstract class:
Non-abstract class:
Which are the different types of design pattern? Explain singleton design pattern.