Hi guys lets get into an interesting topic that is (OOPS)- Object Oriented Programming Language, There are five different topics under this... We can see one by one in this class,
* INHERITANCE
* POLYMORPISM
* ENCAPSULATION
* ABSTRACT
Lets roll into Inheritance.............
{
* INHERITANCE
* POLYMORPISM
* ENCAPSULATION
* ABSTRACT
Lets roll into Inheritance.............
INHERITANCE:
Inheritance is one of the major concept in object oriented.The properties of one object in a class can be extended to the properties of one object in a class can be extended to the properties of object in another hand this is called as inheritance.
Inheritance uses the keyword extends , which is used to extend the properties from one class to another class. Inheritance have the two main terms they are the super class and the subclass there are various type of inheritance are used in java they are
* Single Inheritance
* Multilevel Inheritance
* Hierarchy Inheritance
SINGLE INHERITANCE:
Single inheritance extends the properties from one class to the another class like the class B extends the properties of A.
class A
{
}
public class B extends A{
public static void main (String args[])
{
}
}
MULTILEVEL INHERITANCE:
Multilevel inheritance extends the properties from one class to the another class like the class C extends the properties of B and B extends the properties of A.
class A
{
}
class B extends A
{
}
public class C extends B
{
public static void main (String args[])
{
}
}
HIERARCHY INHERITANCE:
Hierarchy inheritance extends the properties from one class to the another class like the class C extends A and also the class B extends A.
class A
{
}
class B extends A
{
}
public class C extends A{
public static void main (String args[])
{
}
}
POLYMORPHISM:
Polymorphism is the ability to take more than one form. For example the same person contain the different behavior based on the time. In java there are two type of polymorphism they are.
* Method overloading
* Method overriding
METHOD OVERLOADING:
Method overloading contain the same return type, same function name with different types of arguments in same class.
Example;
public class MethodOver{
void a()
{
system.out.println(TONY);
}
void a(int a)
void a(int a)
{
System.out.println(Rajesh);
}
void a(int a,int b)
{
system.out.println(Ranjith);
}
public static void main(String args[])
{
MethodOver obj=new MethodOver();
obj.a();
obj.a(2);
obj.a(2,3);
}
}
METHOD OVERRIDING:
It contain the same function name, same return type and same arguments in different class.
class A
{
void a()
{
system.out.println(Rajesh);
}
}
}
class B
{
void a ()
{
system.out.println(TOny);
}
}
class C
{
void a()
{
system.out.println(Ranjith);
}
}
public class Methodover{
public static void main (String args[])
{
A obj1=new A();
B obj2=new B();
C obj3=new C();
obj1.a();
obj2.a();
obj3.a();
}
}
}