选择题
class Person {
String name = "No name";
public Person(String nm) {
name = nm;
}
}
class Employee extends Person {
String empID = "0000";
public Employee(String id) {
super(" ");//要调用父类的有参构造方法否则报错
empID = id;
}
}
public class Test01 {
public static void main(String args[]) {
Employee e = new Employee("123");
System.out.println(e.empID);
}
}
public class Test01 {
private static void testMethod(){
System.out.println("testMethod");
}
public static void main(String[] args) {
((Test01)null).testMethod();
//testMethod
}
}
public class Test01{
String str=new String("hello");
char[]ch={'a','b'};
public static void main(String args[]){
Test01 ex=new Test01();
ex.change(ex.str,ex.ch);
System.out.print(ex.str+" and ");
System.out.print(ex.ch);
//hello and cb
}
public void change(String str,char ch[]){
str="test ok";//不改变
ch[0]='c';//改变
}
}
public class Test01{
public static void main(String[] args) {
int i=0;
Integer j = new Integer(0);
System.out.println(j);//0
System.out.println(i==j);//true
System.out.println(j.equals(i));//true
}
}
编程题
题目1
public class UnusualAdd {
public static int addAB(int A, int B) {
int s1 = A&B;
// System.out.println(s1);
int s2 = A|B;
// System.out.println(s2);
int c = s1+s2;
return c;
}
}