包 命令行的输入命令 import 以及 public private defual protected

package utill2;
import utill.Person;
import utill1.School;
import utill0.Bike;

public class Demo {
	public static void main (String args[]) {
		 // Person person = new Person();
		 // person.setHome("南京市浦口区天华南路128号");
		 // person.setName("小明");
		Bike bike = new Bike("ofo", "黄色", 3980);
		
		School school = new School("北京东路小学", "解放东路303号");
		// Person d = new Person(new Bike("共享单车ofo", "黄色", 3980), new School("解放东路303号" ,"北京东路小学"));
		 // Person b= new School("解放东路303号","北京东路小学");//
		 // Bike bike = new Bike();
		 // bike.setName("共享单车ofo");
		 // bike.setColour("黄色");
		 // bike.setPrice(3980);


		 Person person= new Person(bike,school);
		 person.setHome("南京市浦口区天华南路128号");
		 person.setName("小明");
		 // School school = new School();
		 // school.setSite("解放东路303号");
		 // school.setName("北京东路小学");
		
		// person.setBike(bike);
		// person.setSchool(school);
		// Bike bike = new Bike("共享单车ofo", "黄色", 3980);//Bike bike = new Bike("ofo", "黄色", 3980, school);
		person.cease();
		// System.out.println(person.getSchool());
	}
}



package utill0;

public class Bike {
	private String name;
	private String colour;
	private int price;
	
	public Bike() {

	}

	public Bike(String name, String colour, int price) {
		this.name = name;
		this.colour = colour;
		this.price = price;
	}

	public void setName(String name) {
		this.name = name;
	}
	public String getName() {
		return name;
	}

	public void setColour(String colour) {
		this.colour = colour;
	}
	public String getColour() {
		return colour;
	}

	public void setPrice(int price) {
		this.price = price;
	}
	public int getPrice() {
		return price;
	}

// 	public void cease1() {
// 		System.out.println("骑行");
// 	}
 }


package utill;
import utill0.Bike;
import utill1.School;

public class Person {
	private String home;
	private String name;
	private Bike bike;
	private School school;
	
	public Person() {

	}

	public Person(Bike bike, School school) {
		// this();this可以调用第二个构造方法,但必须写在构造函数的第一行,所以一个构造函数最多只能多调用一个构造方法
		this.bike = bike;
		this.school = school;
	}

	public void setHome(String home) {
		this.home = home;
	}

	public String getHome() {
		return home;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public void setBike(Bike bike) {
		this.bike = bike;
	}

	public Bike getBike() {
		return bike;
	}

	public void setSchool(School school) {
		this.school = school;
	}

	public School getSchool() {
		return school;
	}

	public void cease() {
		System.out.println(live()+home+"的"+name+"骑着"+bike.getPrice()+bike.getColour()+bike.getName()+school.getSite()+school.getName()+"考试");
		// bike.cease1(); 可以定义自行车的行为
	}

	public String live() {
		return "家住";
	}

	public String ride() {
		return "骑着";
	}

	public String exam() {
		return "考试";
	}
}


package utill1;

public class School{
	private String site;
	private String name;
	
	public School() {

	}

	public School(String site, String name) {
		this.site = site;
		this.name = name;
	}
	public void setSite(String site) {
		this.site = site;
	}
	public String getSite() {
		return site;
 	}

 	public void setName(String name) {
		this.name = name;
	}
	public String getName() {
		return name;
 	}
}





注意事项:导包的类必须都分开 package 必须都在第一行 improt导入到另外一个类的 是有联系的有值传进来的就需要导入。 把源文件都放在classes文件夹里 把编译好的文件都放在src文件夹里;

需要的命令行命令是:

202004_bdXb_3708604.png

 

 

 

 

 

转载于:https://my.oschina.net/u/3708604/blog/1556264

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值