【单选题】(06-03) 下面 Java 代码的运行结果是 ( ) 。 class Penguin { private String name=null; // 名字 private int health=0; // 健康值 private String sex=null; // 性别 public void Penguin() { health = 10; sex = " 雄 "; Syst
举一反三
- (06-03)下面Java代码的运行结果是。 class Penguin { private String name=null; // 名字 private int health=0; // 健康值 private String sex=null; // 性别 public void Penguin() { health = 10; sex = "雄"; System.out.println("执行构造方法。"); } public void print() { System.out.println("企鹅的名字是" + name + "健康值是" + health + "性别是" + sex+ "。"); } public static void main(String[] args) { Penguin pgn = new Penguin(); pgn.print(); } }
- class Person{ static{ System.out.println(name); } private static String name = "hello"; } class Demo{ public static void main(String[] args){ Person p = null; } }
- 下列程序的运行结果是( )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();}}
- 请填写代码 public class Teacher { int age=33; private string name; public string Name { get{请在此处填上代码} set{请在此处填上代码} } } public void SaySomething{ //….. }
- 从下面四段代码中选择出正确的代码段() A: public class Something {public static void main(String[] args) {Other o = new Other();new Something().addOne(o);}public void addOne(final Other o) {o.i++;}}class Other {public int i;} B: public class Something {void doSomething () {private String s = ̶”;int l = s.length();}} C: abstract class Name {private String name;public abstract boolean isStupidName(String name) {}} D: public class Something {public int addOne(final int x) {return ++x; }}