Use keyword super to access attribute of superClass(Parent Class)
/**
* @author lautturi.com
* Java example:
*/
import java.util.*;
class Animal {
protected String type = "animal";
}
class Dog extends Animal {
public String type = "mammal";
public void printType() {
System.out.println("I am a " + type);
System.out.println("I am an " + super.type);
}
}
public class Lautturi {
public static void main(String[] args) {
Dog dog1 = new Dog();
dog1.printType();
}
}Source:w.wwlautturi.comoutput:
I am a mammal I am an animal