Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,18 @@

public class Test {
public static void main(String[] args) {
// Creating an instance of Dog class
Dog dog = new Dog("Buddy",5); // Initializing the dog with name "Buddy" and age 5

// Displaying the dog's name and age using getter methods
System.out.println("Dog's name: "+dog.getName());
System.out.println("Dog's age: "+dog.getAge());

//Calling the sayHello() method of the dog. Since it has overridden the method of the Animal class, it will print "Wolf"
dog.sayHello(); // Output: Wolf

// Calling the eat() method of the dog. Since Dog class doesn't override eat() method of the Animal class, so Animal class's eat() will be called
dog.eat(); // Output: This animal eats food.

}

}