Parts of a class and their names
public class Dog extends Mammal
//superclass of dog is mammal
{
String name;
//Instance Variable
boolean happy;
//Instance Variable
public Dog()
//Header for a constructor
{
name = "Fido";
happy = true;
}
public void setHappy(boolean h)
//setter Method
{
happy = h;
}
public String isHappy()
//getter Method with String return type
{
return happy;
}
public void setName(String aName)
//setter Method
{
name = aName;
}
public String getName()
//getter Method with String return type
{
return name;
}
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.