简单的面向对象类的写法

package com.phome.test1;

public class Student {
	String stuName="王海";
	int stuNo=001;
	String stuGender="男";
	
	public void study(){
		System.out.println(stuName+"正在学习。");
	}
}

package com.phome.test1;

public class Teacher {
	String teaName="张三";
	int teaNo=1001;
	String teaGender="女";
	
	public void teach(){
		System.out.println(teaName+"正在授课。");

	}
	
}
package com.phome.test1;

public class Building {
	String buildName="艺术楼";
	int buildNo=514;
	
	
	public void used(){
		System.out.println(buildNo+"教室正在被使用。");
	}
}

package com.phome.test1;

public class Dog {
	String dogName="点点";
	String dogColor="黑";
	
	public void eat(){
		System.out.println(dogName+"正在找吃的");
	}
}

package com.phome.test1;

public class Tree {
	String treeType="柏树";
	String treeColor="绿";
	
	public void walf(){
		System.out.println(treeType+"正在风中摇曳。");
	}
}

package com.phome.test1;

public class School {

	Student student = new Student();
	Teacher teacher = new Teacher();
	Building building = new Building();
	Dog dog = new Dog();
	Tree tree = new Tree();

	public String toString() {

		System.out.println(student.stuName);
		System.out.println(student.stuNo);
		System.out.println(student.stuGender);
		student.study();
		System.out.println(teacher.teaName);
		System.out.println(teacher.teaNo);
		System.out.println(teacher.teaGender);
		teacher.teach();
		System.out.println(building.buildName);
		System.out.println(building.buildNo);
		building.used();
		System.out.println(dog.dogName);
		System.out.println(dog.dogColor);
		dog.eat();
		System.out.println(tree.treeType);
		System.out.println(tree.treeColor);
		tree.walf();
		return "";
	}

}

package com.phome.test1;

public class SchoolTest {
	public static void main(String[] args) {
		School school=new School();
		System.out.println(school);
	}
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值