Untitled
unknown
plain_text
a year ago
691 B
3
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