Inheritance:-Inheritance is the process by which one object acquires the properties of another object.
There are 3 types of inheritance in java
1. Single level Inheritance:-
When class uses another class then we use extends or when class uses inheritance of another class then we use implements.
class Inher{
There are 3 types of inheritance in java
1. Single level Inheritance:-
When class uses another class then we use extends or when class uses inheritance of another class then we use implements.
class Inher{
void
mobile(){
System.out.println("Samsung");
}
}
class
Main extends Inher{
void
laptop(){
System.out.println("Acer");
}
public
static void main(String args[]){
Main
m=new Main();
m.laptop();
m.mobile();
}
}
OUTPUT:-
C:\Users\Satyendra\Desktop>javac
Main.java
C:\Users\Satyendra\Desktop>java
Main
Acer
Samsung
No comments:
Post a Comment