class Animal { public Animal() { System.out.println("Animal!"); } } public class Dog extends Animal{ public Dog() { System.out.println("Dog!"); } public static void main(String[] args) { Dog dog=new Dog(); } }
举一反三
- 下列各种java类的定义,那种是错误的 A: class Animal{}class Dog extends Animal {} B: final class Animal{}class Dog extends Animal{} C: abstract class Animal{}class Dog extends Animal{} D: public class Animal{}class Dog extends Animal{}
- 阅读下段代码, class Dog { public String name; Dog(String name){ this.name =name; }} public class Demo1 { public static void main(String[] args){ Dog dog1 = new Dog("xiaohuang"); Dog dog2 = new Dog("xiaohuang"); String s1 = dog1.toString(); String s2 = dog2.toString(); String s3 = "xiaohuang"; String s4 = "xiaohuang"; } } 返回值为true的是()
- 判断如下代码是否存在1处语法错误(正好存在1处错误为正确,少于1处或者多余1处都为错误):public class Animal{ }class Dog extends Animal{ String name; public Dog(){ this.name = "阿毛"; super();}}
- public class Dog(){...}下列哪个选项可以是Dog类的构造方法 A: public Dog(){ } B: public void Dog(){ } C: public dog(){ } D: public void dog(){ }
- 对于下列代码,下列哪个叙述是正确的? abstract class Animal { int m = 100; abstract public void f(); } class Dog extends Animal { int m; } public class E { public static void main(String args[]) { System. out. println(new Dog(). m);// [代码] } } A: 程序提示编译错误(Dog不是抽象的,并且未覆盖,即重写Animal中的抽象方法f() )。 B: 编译无错误,[代码]输出0。 C: 编译无错误, [代码]输出100。 D: 编译无错误, [代码]输出null。