What's new

Java Java program patulong

Joined
Dec 11, 2020
Posts
109
Reaction
158
Points
78
The cat, the dog, and the horse
are types of animals that would be represented by subclasses of the Animal
class. Animal class has the methods sound(), eat(), and sleep(). Include also
attributes such as Name and Breed. Construct a Java program that will show inheritance
for the sample scenario.

Patulong please huhuhu
 
try mo yan boss...

class Animal:
def init(self,Name,Breed):
self.Name = Name
self.Breed = Breed

def sound(self):
print("awawaw")
def eat(self):
print("num num num")
def sleep(self):
print("zzZ")

mypet = Animal("choco","Chuwawa")
mypet.sound()
mypet.eat()
mypet.sleep()
 
animal class is your super class which has 3 following constructors. eat sleep sound. easy lang yan.

just dont forget to put "extends" to your subclass in order for the child class to inherit methods of the parent class


example

class Dog extends Animal

that means the child class can inherit or basically can call any methods/constructors publicly declared in the parent class
 
Last edited:

Similar threads

Back
Top