1:实体变量:对象本身已知的事物
方法:对象可执行的动作
2:类不是对象:类比关系是按钮类和各色按钮,狗和各种狗
3:``用惯了c写数据结构题,突然转到java中对象里的嵌套调用微微不适。
习题2:
class DrumKit{
boolean topHat=true;
boolean snare=true;
void playTopHat(){
System.out.println("ding ding da-ding");
}
void playSnare(){
System.out.println("bang bang ba-bang");
}
}
public class DrumKitTeatDrive{
public static void main(String[] args){
DrunKit d= new DrumKit();
if(d.snare==true){
d.playSnare();
}
d.snare=false;
d.playTopHat();
}
}
习题3
class Echo{
int count=0;
void hello(){
Systrm.out.println("hellooooo..");
}
}
public class EchoTestDrive{
public static void main(String[] args){
Echo e1=new Echo();
Echo e2=new Echo();
int x=0;
while(x<4){
e1.hello();
e1.count=e1.count+1;
if(x==4)
e2.count=e2.count+1;
if(x<5)
e2.count=e2.count+e1.count;
x+=1;
}
System.out.println(e2.count);
}
}