学了一阵子基础,做做题目. 记录--5.31

Posted on 2007-05-31 14:59 yiraka 阅读(230) 评论(0)  编辑  收藏 所属分类: scjp

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是私有成员.



只有注册用户登录后才能发表评论。


网站导航:
 

posts - 8, comments - 0, trackbacks - 0, articles - -1

Copyright © yiraka