下面哪个程序变量age的定义是正确的()
A: public class Employee{ public void show(){ System.out.println(age); } public int age; }
B: public class Employee{ public void show(){ System.out.println(age); int age = 20; } }
C: public class Employee{ public void show(){ System.out.println(age); } }
A: public class Employee{ public void show(){ System.out.println(age); } public int age; }
B: public class Employee{ public void show(){ System.out.println(age); int age = 20; } }
C: public class Employee{ public void show(){ System.out.println(age); } }
举一反三
- 有如下类的定义,创建Employee对象正确的是() public class Employee{ private int age; private String name; public void Employee(){ } public Employee(int age){ this.age = age; } public Employee(String name){ this.name = name; } } A: Employee e = new Employee( ) B: Employee e = new Employee(10); C: Employee e = new Employee(tom); D: Employee e = new Employee(10,"tom");
- public class Example { public static void main(String[] args) { new Father () { public void show() { System.out.println("helloworld"); } }.show(); } } class Father { public void show() { System.out.println("hellofather"); } }
- 分析下面的程序,输出的结果是? public class Test { public static void main(String[] args) { final Person p = new Person("张三", 23); p.setName("李四"); p.setAge(24); System.out.println(p); } } class Person { private String name; private int age; public Person() { super(); } public Person(String name, int age) { super(); this.name = name; this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public String toString() { return "我的姓名是:" + name + ",我的年龄是:" + age ; } }
- 有如下类的定义,创建Employee对象错误的是() public class Employee{ private int age; private String name; public Employee(int age){ this.age = age; } public Employee(String name){ this.name = name; } public Employee(int age,String name){ this(age); this.name = name; } } A: Employee emp = new Employee(10); B: Employee emp = new Employee("Tom"); C: Employee emp = new Employee(); D: Employee emp = new Employee(10,"Tom");
- 【填空题】public class ThisTest{ private String name; private int age; public ThisTest() { System.out.println("产生一个新的Person对象。"); } public ThisTest (String name, int age) { this(); this.name = name; this.age = age; } public String getInf() { return "姓名:" + name + ",年龄:" + age; } public static void main(String[] args) { ThisTest per = new ThisTest("张三", 20); System.out.println(per.getInf()); } } 运行结果为:____