JAVA程序 特急!!!!!!!!!!送分!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JAVA程序 特急!!!!!!!!!!送分!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!相关的知识,希望对你有一定的参考价值。
1.创建一个类car
其中定义
1>一个属性叫做汽车名字 carname
方法为
2>.setCarname
3>.getCarname
2.创建一个类bmw调用car里面的方法进行输出 "汽车名字为:任意定义的汽车名"
1>main函数写在bmw类里面
2>用car类的setCarname方法定义汽车名字
3>用car类的getCarname方法打印汽车名字
4>bmw类里面没有属性
public class Car
private String carName;
public String getCarName()
return carName;
public void setCarName(String carName)
this.carName = carName;
public Car()
System.out.println("汽车名字为:任意定义的汽车名");
在写BMW类保存为BMW.java:
public class BMW extends Car
/**
* @param args
*/
public static void main(String[] args)
// TODO Auto-generated method stub
BMW bmw = new BMW();
bmw.setCarName("BMW X8");
System.out.println(bmw.getCarName());
参考技术B 演示继承关系,当子类继承父类的时候就包括父类的所有方法了,
实例话的时候 实例本身就够用了
//父类
public class Car
private String CarnName;
/**
* @return the carnName
*/
public String getCarnName()
return CarnName;
/**
* @param carnName the carnName to set
*/
public void setCarnName(String carnName)
CarnName = carnName;
//子类
public class BWL extends Car
public static void main(String []args)
BWL bwl=new BWL();
bwl.setCarnName("宝马");
System.out.println(bwl.getCarnName());
参考技术C class Car
private String carname;
public void setCarname(String name)
carname = name;
public String getCarname() return carname;
public class BMW extends Car
public BMW(String carname)
setCarname(carname);
public static void main(String[] args)
Car car = new BMW("任意定义的汽车名");
System.out.println("汽车名字为:" + car.getCarname());
参考技术D public class BMW
public static void main(String[] args)
Car car = new Car();
car.setCarName("My Car");
System.out.println(car.getCarName());
class Car
private String carName;
public String getCarName()
return carName;
public void setCarName(String carName)
this.carName = carName;
本回答被提问者采纳
以上是关于JAVA程序 特急!!!!!!!!!!送分!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!的主要内容,如果未能解决你的问题,请参考以下文章