🔒 Closed Java program patulong

Status
Not open for further replies.

Baka Renejay to

Enthusiast
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
 
Status
Not open for further replies.

About this Thread

  • 2
    Replies
  • 1K
    Views
  • 3
    Participants
Last reply from:
FreeAllYouCan-OFFICIAL

Trending Topics

Online now

Members online
1,064
Guests online
824
Total visitors
1,888

Forum statistics

Threads
2,274,941
Posts
28,959,487
Members
1,233,488
Latest member
lea11sales
Back
Top