Java Reference
In-Depth Information
< Day Day Up >
Puzzle 48: All I Get Is Static
The following program models the behavioral difference between Basenjis and other dogs. In case
you didn't know, the Basenji is a breed of small, curly-tailed dogs of African origin that do not bark.
What does the program print?
class Dog {
public static void bark() {
System.out.print("woof ");
}
}
class Basenji extends Dog {
public static void bark() { }
}
public class Bark {
public static void main(String args[]) {
Dog woofer = new Dog();
Dog nipper = new Basenji();
woofer.bark();
nipper.bark();
}
}
Solution 48: All I Get Is Static
 
 
Search WWH ::




Custom Search