// to access a property 'num' from SuperClass:
super.num //or
((SuperClass)this).num
// to run the constructor of SuperClass:
super()
class Animal { // Superclass (parent)
public void animalSound() {
System.out.println("The animal makes a sound");
}
}
class Dog extends Animal { // Subclass (child)
public void animalSound() {
super.animalSound(); // Call the superclass method
System.out.println("The dog says: bow wow");
}
}
public class Main {
public static void main(String args[]) {
Animal myDog = new Dog(); // Create a Dog object
myDog.animalSound(); // Call the method on the Dog object
}
}
class Shape {
public void draw() {
System.out.println("Shape draw.");
}
}
class Circle extends Shape {
@Override
public void draw() {
System.out.println("Circle draw.");
super.draw(); // Access parent's version of draw
}
}
public class Main {
public static void main(String[] args) {
Circle c = new Circle();
// The below prints:
// Circle draw.
// Shape draw.
c.draw();
}
}
class Animal {
public void displayInfo() {
System.out.println("I am an animal.");
}
}
class Dog extends Animal {
public void displayInfo() {
super.displayInfo();
System.out.println("I am a dog.");
}
}
class Main {
public static void main(String[] args) {
Dog d1 = new Dog();
d1.displayInfo();
}
}