package Errorlist;
public class ErrorTest3 {
}
21-------------------------------------------------
class Res{
private String name;
private String sex;
private boolean flag = false;
public synchronized void set(String name,String sex){
if(flag)
try{this.wait();}catch(Exception e){}
this.name = name;
this.sex = sex;
flag = true;
this.notify();//这里唤醒的是谁?this指的是谁?为什么打印的结果男女可以交替进行的??
这里this指的是当前线程,那么this指的也是当前的对象,但是这里wait方法要在循环里才行,所以使用if语句判断肯定会出现安全问题。因为定义了标记,标记是交替让线程执行,所以可以交替打印
}
public synchronized void out(){
if(!flag)
try{this.wait();}catch(Exception e){}
System.out.println(name+"……"+sex);
flag = false;
this.notify();
}
}
class Input implements Runnable{
private Res r ;
Input(Res r){
this.r = r;
}
public void run(){
int x = 0;
while(true){
if(x==0)
r.set("mike","man");
else
r.set("丽丽","女女女女女");
x = (x+1)%2;
}
}
}
class Output implements Runnable{
private Res r ;
Output(Res r){
this.r = r;
}
public void run(){
while(true){
r.out();
}
}
}
//多线程通信,多个线程同时操作同个资源
public static void method_3() {
Res r = new Res();
new Thread(new Input(r)).start();
new Thread(new Output(r)).start();
Input in = new Input(r);
Output out = new Output(r);
Thread t1 = new Thread(in);
Thread t2 = new Thread(out);
t1.start();
t2.start();
}
22----------------------------------------------------------
无标题文档
好友列表
好友
好友
好友
好友列表
好友
好友
好友
好友列表
好友
好友
好友
好友列表
好友
好友
好友
为什么展开的效果不对,点上去结果把div隐藏掉了,我需要的是把好友列表隐藏了。
class Base{
private int i = 2;
Base(){
System.out.println("base:"+this.i); //
this.display();//这个this的问题相当大,他指代的是父类对象的引用才对,
// this.show();
}
public void display(){
System.out.println("base display:"+this.i); // 在super()时,这句话未被执行,看打印的结果就知道执行了子类的display
}
}
class Derived extends Base {
public int i = 22;//这里加上static修饰符的话
public Derived(){
super();
i = 222; //
}
public void display(){
System.out.println("derived display:"+i);
}
// public void show(){
// System.out.println("show…run");
// }
}
public class Test3 {
public static void main(String[] args){
new Derived().display();
Test3 test =new Test3();
}
public static void show(){
}
//问:打印结果?
int a = 0, b = 3;
a = b++ + b++ + b-- - --b;
// 我是这样想的,b的运算结果:(1)b=3+1 + (2)b=4+1 + (3)b=5-1 - (4)b=-1+4 ;
//第一个b++在运算的时候b=3参与运算,然后自增为b=4,到第二个b++的时候b=4参与运算,然后自增为b=5,
//到b--的时候b=5参与运算,然后自减为b=4,到--b的时候,b=4先自减为b=3然后参与运算
//所以a=3+4+5-3 -->a=9
System.out.println("a=" + a + ";b=" + b)
30-----------------------------------------------------------------------