ݷʱ : 2025/9/17 22:29:43һ µȫĶ
System.out.println(\߳С>\+i); } }
}
ʾ£Ψһֹ½ƴ˵
ġж߳Ƿ
class MyThread implements Runnable{ }
public class ThreadAliveDemo {
public static void main(String[] args) { }
MyThread mt=new MyThread(); Thread t=new Thread(mt,\߳\);
System.out.println(\ִ֮߳ǰ>\+t.isAlive()); t.start();
System.out.println(\ִ֮߳>\+t.isAlive()); for(int i=0;i<3;i++){ }
System.out.println(\ִ֮>\+t.isAlive());
System.out.println(\С>\+i);
public void run(){ }
for(int i=0;i<3;i++){ }
System.out.println(Thread.currentThread().getName()+\
>\+i);
}
ʾ£֪˼
һ һ̵̵꣬пж֣ûԱʾ
ֹϵҪԸݳĹؼֲѯӦijϢϢ
ơ£
1 ҪʾϢƣԴʱƳ֡ɫ3
ԡ
2 ܶ࣬èȶڳԳӦһ 3 ڳ̵УֻҪǷϴ˳ľӦÿԷŽ̵С
4 ̵Ҫֳ϶ӦdzĶ飬
Ӧô̵ʱͷܱij
£
interface Pet{ }
class Cat implements Pet{
private String name; private String color; private int age;
public Cat(String name,String color,int age){ }
public String getName(){ }
public String getColor(){ }
return this.color; return this.name; this.setName(name); this.setColor(color); public String getName(); public String getColor(); public int getAge();
this.setAge(age);
}
public int getAge(){ }
public void setName(String name){ }
public void setColor(String color){ }
public void setAge(int age){ }
this.age=age; this.color=color; this.name=name; return this.age;
class Dog implements Pet{ }
class PetShop{
private Pet[] pets; private int foot; private String name;
private String color; private int age;
public Dog(String name,String color,int age){ }
public String getName(){ }
public String getColor(){ }
public int getAge(){ }
public void setName(String name){ }
public void setColor(String color){ }
public void setAge(int age){ }
this.age=age; this.color=color; this.name=name; return this.age; return this.color; return this.name; this.setName(name); this.setColor(color);
this.setAge(age);
}
public PetShop(int len){ }
public boolean add(Pet pet){ }
public Pet[] search(String keyWord){ //ؼֲ
Pet p[]=null; int count=0;
//ȷϿٵĿռСжٸϲѯ for(int i=0;i if(this.pets[i]!=null){ if(this.foot this.pets[this.foot]=pet; this.foot++; return true; return false; if(len>0){ } this.pets=new Pet[len]; this.pets=new Pet[1]; //ٿһռ }else{ }else{ if(this.pets[i].getName().indexOf(keyWord)!=-1||this.pets[i].getC } p=new Pet[count]; int f=0;//ӵλñ for(int i=0;i if(this.pets[i]!=null){ } } count++; //ij olor().indexOf(keyWord)!=-1){ if(this.pets[i].getName().indexOf(keyWord)!=-1||this.pets[i].getC } } return p; } } p[f]=this.pets[i];//ϲѯijϢ f++; olor().indexOf(keyWord)!=-1){ public class PetShopDemo { public static void main(String[] args) { PetShop ps=new PetShop(5); ps.add(new Cat(\è\,\ɫ\,2));//ӳɹ ps.add(new Cat(\è\,\ɫ\,3));//ӳɹ ps.add(new Cat(\è\,\ɫ\,3));//ӳɹ ps.add(new Dog(\\,\ɫ\,3));//ӳɹ ps.add(new Dog(\ë\,\ɫ\,3));//ӳɹ ps.add(new Dog(\ƹ\,\ɫ\,3));//ӳʧ print(ps.search(\\)); } } public static void print(Pet p[]){ for(int i=0;i if(p[i]!=null){ System.out.print(p[i].getName()+\+p[i].getAge()+\+p[i].getAge } } } ()); ʾ ,3,3 ıȽ ObjectṩequalsĬDZȽϵַģܶݽбȽϡ class Persona{ private String name; private int age; public Persona(String name,int age){ } public boolean equals(Object obj){//дObjectеequals() if(this==obj){ //ĵַȣ϶ͬһ } if(!(obj instanceof Persona)){//жϴĶǷPersonʵ return true; this.name=name; this.age=age;