Results 1 to 4 of 4
- 01-22-2011, 02:11 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 2
- Rep Power
- 0
Help with creating new class as a subclass in Java
Hello,
i'm new to Java and trying to learn but i'm having trouble creating a new class - as a subclass.
here is what i'm being asked to do;
Create MoneyFrog as a subclass of Frog. In addition to those inherited from the Frog class, instances of the MoneyFrog class should have three additional private instance variables - two boolean variables called lastReceived and lastGiven and a third type Account called account. Write declarations for these instance variables together with public getter and setter methods for the boolean instance variables lastReceived and lastGiven and a public getter method for account.
here's what i've managed to do but the class will not compile
any help would be appreciatedJava Code:/** * Class MoneyFrog * */ public class MoneyFrog extends Frog { /* instance variables */ private Account account; private boolean lastReceived; private boolean lastGiven; /** * Constructor for objects of class MoneyFrog */ public MoneyFrog() { super(); this.account; this.lastReceived = false; this.lastGiven = false; } /* instance methods */ // i'm not sure what to do here but i've tried// /** * returns the receivers account */ public void account() { } /** * returns the value of the amount lastGiven to the receiver */ public boolean lastGiven() { return this.lastGiven; } /** * returns the value of the amount lastReceived by the receiver */ public boolean lastReceived() { return this.lastReceived; } }
-
the Account getter method should be named getAccount and should return the Account object held by the account variable, not a void.
-
Also you need to write your two setter methods. An example of a setter method for an int variable myIntVariable is something like so:
Java Code:public void setMyIntVariable(int myIntVariable) { this.myIntVariable = myIntVariable; // set the class's myIntVariable with the parameter's value }
- 01-22-2011, 03:06 PM #4
Member
- Join Date
- Jan 2011
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
Super class refering to subclass
By sujith123 in forum New To JavaReplies: 3Last Post: 10-05-2009, 09:00 AM -
Custom Class, Wrapper/Subclass?
By Moncleared in forum Advanced JavaReplies: 3Last Post: 02-09-2009, 11:08 PM -
Super class and Subclass in same source file
By makbar24 in forum New To JavaReplies: 17Last Post: 09-10-2008, 01:24 PM -
subclass vs inner class
By bugger in forum New To JavaReplies: 1Last Post: 01-13-2008, 07:31 PM -
which class is superclass and subclass?
By java_fun2007 in forum New To JavaReplies: 0Last Post: 12-11-2007, 08:55 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks