Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
843 B
3
Indexable
public class NewClass2 {
    public static void main(String[] args){
        Dog dog= new Dog("Buddy", 3);
        Cat cat= new Cat("Whiskers", 2);
        
        dog.makeSound();
        cat.makeSound();
    }
    
}
public class Animal {
    String name;
    int age;
    Animal(String name, int age){
        this.name= name;
        this.age= age;
    }
 
}
public class Dog extends Animal {
   Dog(String name, int age)
   {
       super(name,age);
   }
   void makeSound()
   {
       System.out.println("Dog:");
       System.out.println("The Dog barks.");
   }
    
}
public class Cat extends Animal {
    Cat(String name, int age)
    {
        super(name,age);
    }
    void makeSound()
    {
        System.out.println("Cat: ");
        System.out.println("The cat meows.");
    }
}