Site hosted by Angelfire.com: Build your free website today!
 

Example

TestDog.java

class TestDog {
    public static void main(String[] args) {
        System.out.println("Dog has " + Dog.legs + " legs");
        Dog cookie = new Dog("Cookie", "Jack Hung", "light brown");
        cookie.printInfo();
    }
}
  • Can I have a class method that print all three variables (legs, owner and color)?

  • What is wrong with the following?

    public static void main(String[] args) {
        Dog cookie = new Dog("Cookie", "Jack Hung", "light brown");
        Dog lucky = new Dog("Lucky", "Julia", "light gray");
        lucky.legs = 3;
        System.out.println("Dog has " + Dog.legs + " legs");
        cookie.printInfo();
        lucky.printInfo();
    }