Download What Is Use Of "Super" Keyword In Java? - Software Testing Tutorials graphic type that can be scaled to use with the Silhouette Cameo or Cricut. An SVG's size can be increased or decreased without a loss of quality. All of our downloads include an image, Silhouette file, and SVG file. It should be everything you need for your next project. Our SVG files can be used on adhesive vinyl, heat transfer and t-shirt vinyl, or any other cutting surface
- To refer to the variable of parent class.
- To invoke the constructor of immediate parent class.
- To refer to the method of parent class.
Animal.java
public class Animal {
int age = 40;
Animal(){
System.out.println("Animal is moving.");
}
void welcome(){
System.out.println("Welcome to Animal class.");
}
}
Elephant.java
public class Elephant extends Animal {
int age = 100;
Elephant() {
// To invoke parent class constructor Animal().
super();
System.out.println("Elephant is running.");
welcome();
// Used super.welcome() to call parent class method.
super.welcome();
}
void showAge() {
System.out.println("Average age of Elephant : " + age);
// Used super.age to access parent class variable value.
System.out.println("Average age of Animals : " + super.age);
}
void welcome() {
System.out.println("Welcome to Elephant class.");
}
public static void main(String[] args) {
Elephant c = new Elephant();
c.showAge();
}
}
Output
Animal is moving.
Elephant is running.
Welcome to Elephant class.
Welcome to Animal class.
Average age of Elephant : 100
Average age of Animals : 40
- super.age to refer parent class variable age.
- super() to invoke immediate parent class constructor Animal() and
- super.welcome() to access parent class method.
Download What Is Use Of "Super" Keyword In Java? - Software Testing Tutorials All SVG file downloads also come bundled with DXF, PNG, and EPS file formats. All designs come with a small business commercial license. These SVG cut files are great for use with Silhouette Cameo or Cricut and other Machine Tools.