OOPs Questions Flashcards
Four main principles of OOPS Concepts?
Inheritance
Polymorphism
Data Encapsulation
Abstraction
What is inheritance?
The process by which one class acquires the properties and functionalities of another class is called inheritance
Does Java support Multiple Inheritance?
When a class extends more than one classes then it is called multiple inheritance. Java doesn’t support multiple inheritance
What is Polymorphism?
Polymorphism is the ability of an object to take many forms. The most common use of polymorphism in OOPs is to have more than one method with the same name in a single class.
What are the types of Polymorphism?
static polymorphism and dynamic polymorphism
What is method overriding in Java?
When a sub class (child class) overrides the method of super class(parent class) then it is called overriding. To override a method, the signature of method in child class must match with the method signature in parent class
Can we override a static method?
No, we cannot override a static method in Java.
What is method overloading?
When a class has more than one methods with the same name but different number, sequence or types of arguments then it is known as method overloading
Does Java support operator overloading?
Operator overloading is not supported in Java.
Can we overload a method by just changing the return type and without changing the signature of method?
No, We cannot do this. To overload a method, the method signature must be different, return type doesn’t play any role in method overloading.
Is it possible to overload main() method of a class?
Yes, we can overload main() method in Java.
What is the difference between method overloading and method overriding?
Overloading happens at compile-time while Overriding happens at runtime: The binding of overloaded method call to its definition has happens at compile-time however binding of overridden method call to its definition happens at runtime.
What is static and dynamic binding in Java?
Binding refers to the linking of method call to its body. A binding that happens at compile time is known as static binding while binding at runtime is known as dynamic binding.
What is Encapsulation?
Wrapping of the data and code together is known as encapsulation
What is an abstract class in Java?
An abstract class is a class which can’t be instantiated (we cannot create the object of abstract class), we can only extend such classes. It provides the generalised form that will be shared by all of its subclasses, leaving it to each subclass to fill in the details. We can achieve partial abstraction using abstract classes, to achieve full abstraction we use interfaces.
What is Interface in java?
An interface is used for achieving full abstraction. A class implements an interface, thereby inheriting the abstract methods of the interface.