I'm working on a program for an intro to java class and am supposed to use the following interface:
public Interface Animal{ //The animal is first supposed to "speak" and then it gets to eat //As long as the food supply lasts public void feed(); //The animal eats public void eat(); //The animal "talks" public void talk(); //Print the name of the animal and then number of days //that the food will still last. public void print(); }The assignment says that we're supposed to write an abstract class Pet that has object variables for the names of the animals as well as the food supply (given through a constructor) - but I'm confused at how to use object variables in a constructor to set the names and food supply. Can anyone help?
Maybe this may be of help, java docs on constructors and initiating variables: http://docs.oracle.com/javase/tutorial/java/javaOO/constructors.html , and also this: http://www.coderanch.com/t/253368/java-programmer-SCJP/certification/constructor-abstract-class
DavidKroukamp
Practically a Master Poster
Team Colleague
693 posts since Dec 2011
Reputation Points: 282
Solved Threads: 169