判断如下代码是否存在1处语法错误(正好存在1处错误为正确,少于1处或者多余1处都为错误):public class Animal{ }class Dog extends Animal{ String name; public Dog(){ this.name = "阿毛"; super();}}
举一反三
- 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的是()
- (6-2)定义如下Person类,(1)处合理的代码是。 class Person { String name, department; int age; public Person(String n) { name = n; } public Person(String n, int a) { name = n; age = a; } public Person(String n, int a, String d) { ① department = d; } }
- (7-1)定义了Animal类、Cat类和Dog类,则代码段是正确的。 class Animal{ }; class Cat extends Animal{} class Dog extends Animal{}