Beruflich Dokumente
Kultur Dokumente
} // End of class B
// Driver Class Calls show() from B class
class Test
{ Calls show() from A class
public static void main(String args[])
{
X x1 = new A();
A B C
x1 = new B(); <<sub-classes>>
A super-class variable of type X
pointing to a sub-class instance of type B
x1 = new C(); A super-class variable of type X
pointing to a sub-class instance of type C
class A
{
void show() As show() method has
{
}// End of Method package-private scope
class B extends A
{
public void show() Bs show() method has
{ public scope
} / End of Method
void display()
NO ERROR
{
} / End of Method
class B extends A
{
public void show() Bs show() method has
{ public scope
} / End of Method
void display()
{
} / End of Method
class A
{
protected void show() As show() method has
{
}// End of Method protected scope
class B extends A
{
void show() Bs show() method has
{ package-private scope
} / End of Method
void display()
COMPILE-TIME
{
} / End of Method
class B extends A
{
void show() B cannot override final
{ method from super class A
} / End of Method
void display()
COMPILE-TIME
{
} / End of Method
class A
{
int show(int a, int b)
{
}// End of Method
class B extends A
{
void show(int a, int b)
{
} / End of Method
void display()
{
} / End of Method
Compile-Time Error
(Overridden Methods Cannot Have Different Return Types)
No Error
class A
{
void show(int a, int b)
{
}// End of Method