super keyword at method level super keyword at method level with example super keyword in java this and super keyword in java with example super keyword at method level in java super keyword method level in java with example
Super At Method level:
In order to differ between base class methods and derived class methods, in context of derived class, the methods of the base class must be preceded by keyword “super”.
Syntax:
Super.baseclassmethod();
The following example illustrate the
concept of super keyword at method level.
// BaseDemo.java
Class Basedemo
{
int a;//base class variable
void fun1()//base class method
{
System.out.println(“this
is base class”);
}
}
Class DerivedDemo extends Basedemo
{
int a;//Derived class variable
void fun1() //derived class method
{
System.out.println(“this is derived calss”);
Super.fun1();//super at method level
}
int fun2()
{
int c=super.a+a;//super at variable level
System.out.println(“value of a from base
class is”+super.a);
System.out.println(“value of a from base
class is”+a);
}
}
No comments:
Post a Comment