Professional Documents
Culture Documents
Inheritance
Inheritance
-----------------------------------------------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~INHERITANCE~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-----------------------------------------------------------------------------------
----------------------------------------------------------------------->> final
KEYWORD :
-----------------------------------------------------------------------------------
----------------------------------------------------------------------
->> this KEYWORD :
-----------------------------------------------------------------------------------
----------------------------------------------------------------------
->> static KEYWORD :
-----------------------------------------------------------------------------------
----------------------------------------------------------------------
>> In JAVA we can't implement multiple or herarichal inheritance , if you want
to implement the concept of multiple inheritance that can be possible only with a
interface.
Syntax :
class Parent{
}
class child extends Parent{
}
->> super KEYWORD :
1. class parent{
void sum()
{
SOP)"PArent MEthod call");
}
}
class child extends parent{
void print()
{
SOP("Child Method call");
// Example of Upcasting
}
}
class test
{
PSVM(______)
{
parent p=new child();
p.sum();
p.print(); //It will give error
}
}
2. To remove error
class test{
PSVM(_____)
{
parent p=new child();
p.sum();
// Example of Downcasting.
child c=(child)p;
c.sum();
c.print();
}
}
-----------------------------------------------------------------------------------
----------------------------------------------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ABSTRACT
CLASS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-----------------------------------------------------------------------------------
----------------------------------------------------------------------
** WAP for creating a abstract class named as shape, inside the class declare two
private variable named as 'width' and 'height', also declare one parameterized
constructor and one abstract method named as 'area'. Create 2 subclass square and
rectangle that inherite shape class.
in a subclasses use the same variable that is already decre inside the shape class.
-----------------------------------------------------------------------------------
----------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------------------------------------------------------------
Ques :-