您的位置:首页 > 编程语言 > Java开发

java学习例题:对象的使用

2016-09-03 20:38 281 查看

对于一个纯新手的我来说,写一段代码真是不容易呀!苦逼加到处是bug,快疯了!

/*
题目:建立多个多对象
建立过程;     对象:课程教育
成员变量:英语,数学,语文。
成员方法:听,说,读,写。
*/

class Education{
//成员变量;
String english;
String math;
String chinses;
//成员方法;
public void listen(String name){
System.out.println("好好听课");


public void speak(){
System.out.println("上课不许讲悄悄话");
}

public void read (){
System.out.println("大声的读出来");
}

public void write(){
System.out.println("好记性不如烂笔头");

}



class EducationWay{

   public static void main(String[] args){
//建立对象:
Education work = new Education();
//使用成员变量
work. english="四级";
work. math="线性代数";
work. chinses="朗读";
System.out.println(work. english);
System.out.println(work. math);
System.out.println(work. chinses);
System.out.println("————————————————————");
Education work1 = new Education();
work1. english="六级级";
work1. math="概率论";
work1. chinses="默读";
System.out.println("————————————————————");
Education work3 =work ;
System.out.println(work3. english);
System.out.println(work3. math);
System.out.println(work3. chinses);
System.out.println("————————————————————");
work3. english="1级";
work3. math="线性代数和高数";
work3. chinses="朗读与默读";
System.out.println(work. english);
System.out.println(work. math);
System.out.println(work. chinses);
//使用成员方法
work.listen ("我手机号");
work.speak();

work. read ();

work.write();
}

}

每次就做这么简单的就行了!只是真不容易呀!

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: