🔒 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,081
Guests online
3,086
Total visitors
4,167

Forum statistics

Threads
2,294,385
Posts
29,090,729
Members
1,207,303
Latest member
Jay_172004
Back
Top