阅读下段代码, 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的是()
举一反三
- 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(); } }
- 判断如下代码是否存在1处语法错误(正好存在1处错误为正确,少于1处或者多余1处都为错误):public class Animal{ }class Dog extends Animal{ String name; public Dog(){ this.name = "阿毛"; super();}}
- 阅读程序,下面的哪个选项是正确的?( )。 class ExSuper{ String name; String nick_name; public ExSuper(String s,String t) { name = s; nick_name = t; } public String toString(){ return name; } } public class Example extends ExSuper{ public Example(String s,String t){ super(s,t); } public String toString(){ return name +"a.k.a"+nick_name; } public static void main(String args[]){ ExSuper a = new ExSuper(“First”,“1st”); ExSuper b = new Example(“Second”,“2nd”); System.out.println(“a is”+a.toString()); System.out.println("b is"+b.toString()); } }
- public class Dog(){...}下列哪个选项可以是Dog类的构造方法 A: public Dog(){ } B: public void Dog(){ } C: public dog(){ } D: public void dog(){ }
- 下列程序的运行结果是( )class Demo{private String name;Demo(String name){this.name = name;}private static void show(){System.out.println(name)}public static void main(String[] args){Demo d = new Demo(“lisa”);d.show();}}