Java Reference
In-Depth Information
Listing 6-31. A Test Class to Demonstrate the Use of the SmartDog Class
// SmartDogTest.java
package com.jdojo.cls;
public class SmartDogTest {
public static void main(String[] args) {
// Create two SmartDog objects
SmartDog sd1 = new SmartDog();
SmartDog sd2 = new SmartDog("Nova", 219.2);
// Print details about the two dogs
sd1.printDetails();
sd2.printDetails();
// Make them bark
sd1.bark();
sd2.bark();
// Change the name and price of Unknown dog
sd1.setName("Opal");
sd1.setPrice(321.80);
// Print details again
sd1.printDetails();
sd2.printDetails();
// Make them bark one more time
sd1.bark();
sd2.bark();
}
}
Using SmartDog() constructor
Using SmartDog(String, double) constructor
Name: Unknown, price: Free
Name: Nova, price: 219.2
Unknown is barking...
Nova is barking...
Name: Opal, price: 321.8
Name: Nova, price: 219.2
Opal is barking...
Nova is barking...
Search WWH ::




Custom Search