Table of Contents
Introduction: OOPs concept
Java is object oriented programming language, Java Programming language is very popular in software industry because of OOPs concept, OOPs concept provides 5 important pillars.
Top 20 Software Testing Interview Questions
Inheritance:
it is one of the object oriented principle where one class acquires properties of other class with the help of ‘extends’ keyword is known as Inheritance
example:
public class Prog1{
methods
}
public class Prog2 extends Prog1{
public static void main(String[] args){
Prog2 ab= new Prog2();
ab.methods;
}
}
Types:
1. Single Level Inheritance: It is a type of inheritance where inheritance takes place between only two classes super class and sub class
2. Multi-level Inheritance : it takes place between three or more than three classes. one sub class acquires properties of super class and that class acquires properties of another super class and phenomena continues.
3. Multiple Inheritance: one sub class acquires properties of two super classes at the same time is known as multiple inheritance.
but java doesn’t support it due to ambiguity problem.
by using interface we can achieve multiple inheritance, as interface don’t have object class.
4. Hierarchical Inheritance: when two or more than two sub classes acquires properties of one super class is known as hierarchical inheritance.
Polymorphism:
it is one of the object oriented principle where one object showing different behavior at different stages of life cycle is known as polymorphism.
Types:
- Compile time Polymorphism/ static Polymorphism:
when method declaration is going to gets binded to its definition during compilation time based on arguments passed is known as compile time polymorphism.
example: Method Overloading: when we write multiple methods with same name and differentiate with different parameter then it is known as method overloading. - Run time Polymorphism/ Dynamic Polymorphism:
it is one type of Polymorphism where method calling is going to gets binded to its definition at run time based on object creation is known as run time Polymorphism.
Example: Method Overriding: when we write method in super class and subclass in such a way that method name as well as parameter passed are same then it is known as method overriding.
Encapsulation:
It is one of the object oriented principle where we can wrap data members and member method in single unit is known as encapsulation.
Note: data member as private and method should be public.
Encapsulation involves bundling data (attributes) and methods that operate on the data within a single unit (class). It restricts access to some of an object’s components, making them private or protected, and provides public methods to interact with the object. (OOPs concept)
Abstraction:
it is one of the object oriented principle where implementation details are kept hidden and only highlighted services are visible to user.
it provides advantages like enhancement and security.
Types: Abstract Class and Interface
Abstract Class:
A class declare with abstract keyword is known as abstract class.
- it may or may not contain abstract method.
- in this class complete as well as incomplete method are present.
- we can’t create object of abstract class so we have concrete class. where we provide definition to all incomplete methods.
- if we kept any method as abstract then that class become abstract class.
- abstract method is a method which id declared only and no definition is provided.
Interface:
It is an user defined prototype where we can write only abstract methods. (OOPs concept)
- An interface in Java is a collection of abstract methods.
- It defines a contract that classes must adhere to if they implement the interface.
- It allows multiple inheritance of method signatures.
- to provide definition to abstract methods we have one implementation class where we provide definition to all the methods.
- we will use implements keyword to assign properties into implementation class.
- we can’t create object of interface.
(OOPs concept) Top 5 IT skill Automation Testing Top 10 Selenium Interview Questions