gutxgc
发贴: 7
积分: 0
|
于 2006-05-13 11:57
class Phone { 2. static String device = "Phone.device"; 3. void showDevice() { 4. System.out.print("Phone.showDevice," + device + " "); 5. } 6. Phone() { 7. showDevice(); 8. } 9. }
1. class Mobile extends Phone { 2. String device = "Mobile.device"; 3. void showDevice() { 4. System.out.print("Mobile.showDevice," + device + " "); 5. } 6. Mobile() { 7. showDevice(); 8. } 9. public static void main(String[] args) { 10. Mobile n = new Mobile(); 11. n.showDevice(); 12. } 13. }
CHOICES: 1 Mobile.showDevice,Mobile.device Mobile.showDevice,Mobile.device Mobile.showDevice,Mobile.device
2 Phone.showDevice,Phone.device Mobile.showDevice,Mobile.device Mobile.showDevice,Mobile.device
3 Mobile.showDevice,null Mobile.showDevice,Mobile.device Mobile.showDevice,Mobile.device
4 Compile Time error
5 RunTimeException is thrown
The correct answer is 3. Can anyone explain why?
|