Object-oriented programming (OOP) is a programming language 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.
2. Can you write the basic concepts of OOP?
- Abstraction
- Encapsulation
- Inheritance
- Polymorphism
3. What is a class?
A class is a broad definition of something, an instance (or object) is a specific example that fits under that broader class definition. e.g. TV is a class, and my Samsung TV is my instance.
4. What is an object?
It is the actual instance of a class. e.g. Car is class, my Mercedes Benz is an instance.
5. What is Encapsulation?
The Class can encapsulate the details of the logic.
6. What is Polymorphism?
Polymorphism is an object-oriented programming concept that refers to the ability of a variable, function or object to take on multiple forms.
7. What is Inheritance?
One class can extend the features of the other Class, and the first class will be the sub class, usually it implies a more specific type of entity. e.g. Dog is subclass of Pet. Dog is more specific whereas Pet can contain some common features of Pet. This way when I create a class called Cat, I do not need to repeat everything Pet has already got.
9. Define a constructor?
Constructor is a method used to initialise an object, and it gets invoked at the time of object creation. The creation of an object involves allocating the right amount of the memory.
10. Define Destructor?
Destructor is a method which is automatically called when the object is destroyed. You can clean up things there if needed.
12. What is a virtual method?
Virtual method is a member method of class and its functionality can be overridden in its derived or subclass class.
13. What is overloading?
Same method name, but different number or type of parameters.
for e.g.
void add(int a, int b);
void add(double a, double b);
void add(int a, int b, int c);
14. What is an abstract class?
- An abstract class is a class which cannot be instantiated.
- It will be inherited by specific type or class. (A type is a class, a class is a type)
- An abstract class can contain only Abstract method.
15. What is a ternary operator?
condition ? expr1 : expr2
If condition is true, expr1 is executed otherwise expr2 will be executed.
16. What is method overriding?
Method overriding is a feature that allows sub class to provide implementation of a method that is already defined in the main class. This will override the implementation in the super class by providing the same method name, same parameter and same return type.
17. What is an interface?
An interface is a contract.
An interface is a collection of abstract method. If the class implements an inheritance, and then thereby inherits all the abstract methods of an interface.
18. What is exception handling?
Exception is an event that occurs during the execution of a program. Exceptions can be of any type – Run time exception, Error exceptions. Those exceptions are handled properly through exception handling mechanism like try, catch and throw keywords.
19. Difference between class and an object?
An object is an instance of a class. Objects hold information , but classes don’t have any information. Definition of properties and functions can be done at class and can be used by the object. Class can have sub-classes, and an object doesn’t have sub-objects.
20. What is early and late binding?
Early binding refers to assignment of values to variables during design time whereas late binding refers to assignment of values to variables during run time.