1.簡單的一題,錯了.
自動轉型
class Test {
void test(int i){
System.out.println("i");
}
void test(String s){
System.out.println("s");
}
public static void main(String[] args){
Test t=new Test();
char ch='y';
t.test(y);
}
}
運行結果為"i",在編譯自動把字符型轉換為整型!!
2.Reader/Writer只處理Unicode字符的輸入輸出。float和double可以通過stream進行I/O
3.線程
public class Z {
public static void main(String[] args) {
new Z();
}
Z() {
Z alias1 = this;
Z alias2 = this;
synchronized(alias1) {
try {
alias2.wait();
System.out.println(“DONE WAITING”);
}
catch (InterruptedException e) {
System.out.println(“INTERR UPTED”);
}
catch (Exception e) {
System.out.println(“OTHER EXCEPTION”);
}
finally {
System.out.println (“FINALLY”);
}
}
System.out.println(“ALL DONE”);
}
}
alias1,alias2引用同一個對象,當執行wait()方法時,線程放棄對象鎖,因無notifyAll()和notify()方法,{這個方法是把對象的等待池中的線程放入對象的鎖池,以便獲得對象鎖},所以對象一直處于等待的狀態什么也不打印)
13
class Person {
private int a;
public int change(int m){ return m; }
}
public class Teacher extends Person {
public int b;
public static void main(String arg[]){
Person p = new Person();
Teacher t = new Teacher();
int i;
// point x
}
}
A. i = m;
B. i = b;
C. i = p.a;
D. i = p.change(30);
E. i = t.b.
A.m局域變量,等于未定義.B.在靜態方法中不能使用非靜態成員變量,可通過類的實例的引用來調用.
如i=t.b
C.a是私有成員.