One more important interview question. You can prepare the answer in following way:
OOPS abbreviates as Object Oriented Programming System. Java is considered an object-oriented language. It provides many concepts such as following:
OOPS abbreviates as Object Oriented Programming System. Java is considered an object-oriented language. It provides many concepts such as following:
- Inheritance
- Polymorphism
- Abstraction
- Encapsulation
Let's look at each one of them in detail:
What is Inheritance?
What is Inheritance?
Inheritance: There are 2 things involved here. One is Super class or Parent class and another is Subclass or Child class. So, when a subclass inherits the properties of the parent class, it is called as Inheritance. It helps us in code reusability.
What is Polymorphism?
What is Polymorphism?
Polymorphism: You can remember the concept in this way. Poly means many and phism means form. So, when one thing takes multiple forms, it is called Polymorphism. Or when one task is performed in different ways, is known as Polymorphism.
For Example Login as User, Login as Admin, Login as Manager.
In Java, we can achieve Polymorphism is of 2 types:
- Method Overloading
- Method Overriding
- Runtime Polymorphism
- Compile time Polymorphism
Code Example:
public void Add(int a,int b){
int Sum=0;
Sum=a+b;
System.out.println("The addition is": +Sum);
}
public void Add(float a ,float b){
float Sum=0;
Sum=a+b;
System.out.println("The addition is": +Sum);
}
At runtime, you provide 2 int values, first Add() will be invoked and if you provide 2 float values, then second Add() will be invoked.
Please come back here to read about the remaining concepts. We will discuss on Abstraction and Encapsulation.
Please give your comments so that we know how we are doing.
Thank you for reading! I hope, it will help you.
0 comments:
Post a Comment