OOPs Questions Flashcards
(42 cards)
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.
What is the difference between abstract class and interface?
1) abstract class can have abstract and non-abstract methods. An interface can only have abstract methods.
2) An abstract class can have static methods but an interface cannot have static methods.
3) abstract class can have constructors but an interface cannot have constructors.
Name the access modifiers that can be applied to the inner classes?
public ,private , abstract, final, protected.
What is a constructor in Java?
Constructor is used for creating an instance of a class, they are invoked when an instance of class gets created. Constructor name and class name should be same and it doesn’t have a return type.
Can we inherit the constructors?
No, we cannot inherit constructors.
Can we mark constructors final?
No, Constructor cannot be declared final.
What is a default constructor?
Constructors with no arguments are known as default constructors, when you don’t declare any constructor in a class, compiler creates a default one automatically.
What is a parameterized constructor?
Constructor with arguments are known as parameterized constructors.
Can a constructor call another constructor?
Yes. A constructor can call the another constructor of same class using this keyword. For e.g. this() calls the default constructor. Note: this() must be the first statement in the calling constructor.