Super Keyword in Java
Super Keyword in Java
is used.
class Animal{
String color="white";
class TestSuper1{
public static void main(String args[]){
Dog d=new Dog();
d.printColor();
}}
The output:black
white
int id;
String name;
void set_data()
{
try{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter the Id:");
id=Integer.parseInt(br.readLine());
System.out.println("Enter the Name");
name=br.readLine();
}catch(Exception ex){ex.printStackTrace();}
}
void display()
{
System.out.print(id+"\t"+name+"\t");
}
}
}catch(Exception ex){ex.printStackTrace();}
}
void display ()
{
super.display();
System.out.println(desgn+"\t"+sal);
}
Eg_2:
class Person1 {
int id;
String name;
void set_data(int id,String name)
{
try{
this.id=id;
this.name=name;
}catch(Exception ex){ex.printStackTrace();}
}
void display()
{
System.out.print(id+"\t"+name+"\t");
}
}
}catch(Exception ex){ex.printStackTrace();}
}
void display()
{
super.display();
System.out.print(desgn+"\t"+sal);
}
int id;
String name;
public Person()
{
try{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter the Id:");
id=Integer.parseInt(br.readLine());
System.out.println("Enter the Name");
name=br.readLine();
}catch(Exception ex){ex.printStackTrace();}
}
void display()
{
System.out.print(id+"\t"+name+"\t");
}
}
}catch(Exception ex){ex.printStackTrace();}
}
void display ()
{
super.display();
System.out.println(desgn+"\t"+sal);
}
this.id=id;
this.name=name;
}catch(Exception ex){ex.printStackTrace();}
}
void display()
{
System.out.print(id+"\t"+name+"\t");
}
}
}catch(Exception ex){ex.printStackTrace();}
}
void display()
{
super.display();
System.out.print(desgn+"\t"+sal);
}