举一反三
- 有如下类的定义,创建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");
- 有如下类的定义,创建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");
- 关于Employee类的对象说法错误的是() public class Employee{ private int age; private String name; public Employee(){ } public Employee(int age,String name){ this.age = age; this.name = name; } } public class TestEmployee{ public static void main(String[] args){ Employee e1 = new Employee(); Employee e2 = new Employee(10,"tom"); Employee e3 = e2; Employee e4 = new Employee(10,"tom"); } } A: e1对象的name和age属性的值是默认值null和0 B: e2和e3指向相同的内存空间,即指向同一个对象 C: e3和e4对象的age属性值都是10,name属性值都是"tom",所以是同一个对象 D: 表达式e2==e3的值为true,e3==e4的值为false
- 现有表Employee,字段:id(int)、firstname(varchar)、lastname(varchar);以下sql语句错误的是()
- 在Java中,创建对象必须使用的关键字是【 】 A: class B: int C: new D: private
内容
- 0
在员工管理系统中,查询表employee表中所有员工的姓名,字段:id(int),firstname(varchar),lastname(varchar),以下sql语句正确的是()。 A: Select firstname +’.’+ lastname as ‘name’ from employee B: Select firstname +’.’+ lastname from employee C: Select ‘name’= firstname +’.’+ lastname from employee D: Select firstname,lastname from employee
- 1
给出下列代码,如何使成员变量m被方法fun()直接访问?class Test { private int m; public static void fun( ) { ... }} A.将 private int m 改为protected int m B.将private int m 改为public int m C.将private int m改为static int m D.将private int m改为int m
- 2
给出如下代码: class Test{ private int m(){ ...... } public static void fun() { ...... } } 如何使成员函数m() 被函数fun()直接访问 A: 将private int m() 改为protected int m() B: 将private int m() 改为 public int m() C: 将private int m() 改为 static int m() D: 将private int m() 改为 int m()
- 3
下列定义类的格式,和创建对象格式正确的是() A: public class Cell{ private int row; int col; public void getCellInfo(){System.out.println(row+":"+col); }} B: 创建对象的格式:Cell c=new Cell(); C: public class Cell(){ private int row; int col; public void getCellInfo(){System.out.println(row+":"+col); }} D: 创建对象的格式:Cell c=new Cell;
- 4
(6-3)阅读程序,写出程序运行结果。 class Book{ private static int counter=0; private int id=1; private String name; public Book(String name) { this.name = name; counter++; this.id=this.id+8; } public static int getCounter() { return counter; } public int getID() { return this.id; } } public class BookDemo{ public static void main(String[] args) { Book b1=new Book("红楼梦"); Book b2=new Book("西游记"); Book b3=new Book("儒林外史"); System.out.println(b3.getCounter()*Book.getCounter()*b3.getID()); } }