文档库 最新最全的文档下载
当前位置:文档库 › 06_类和对象

06_类和对象

06_类和对象
06_类和对象

3.2练习

通过方法访问对象的属性

阅读下面代码并添加注释,分析程序运行结果

1

public class Demo1 {

int age;

public void printAge(){

System.out.println(age);

}

public void setAge(){

age =99;

}

public static void main(String[] args) {

Demo1 demo = new Demo1();

demo.printAge();

demo.setAge();

demo.printAge();

}

}

2

public class Test {

public static void main(String[] args) {

Demo1 demo = new Demo1();

Demo1 temp = new Demo1();

demo.printAge();

temp.printAge();

demo.setAge();

demo.printAge();

temp.printAge();

}

}

3

public class Demo2 {

public void fun(){

int m ;

System.out.println(m);

}

public static void main(String[] args) {

Demo2 demo = new Demo2();

demo.fun();

}

}

public class Demo2 {

public void fun(){

int m =8;

}

public static void main(String[] args) {

Demo2 demo = new Demo2();

System.out.println(demo.m);

}

}

4按下面的描述编写程序

定义类,类名是老师

类内定义方法 发言,实现功能:输出信息

定义类 类名是学生,

类内定义方法,发言,实现功能:输出信息定义类,类名是学校

类内定义方法 开会

老刘的代码怎么写?于海东的代码怎么写?你的代码怎么写

如果你分配的任务,有程序员不满意怎么办?应该如何分配开发任务?

象,调用它们的方法 发言

的对象,调用开会方法

力的小游戏程序实现下面的功能,2,安排于海东完成3,4,5

如何分配开发任务?

相关文档