Untitled
Anonymous
plain_text
10/04/2024 9:01 AM
924 B
21
Indexable
class Animal {
Animal() {
System.out.println("Animal constructor called.");
}
void display() {
System.out.println("This is an animal.");
}
}
class Dog extends Animal {
Dog(int i) {
System.out.println("Dog constructor called."+i);
}
Dog(int i ,int j) {
System.out.println("Dog constructor called."+i+ j);
}
void bark() {
System.out.println("The dog barks.");
}
}
public class InheritanceWithConstructor {
public static void main(String[] args) {
Dog myDog = new Dog(1);
Dog shemdi = new Dog(1,2);
myDog.display();
myDog.bark();
}
}
Editor is loading...
Leave a Comment