class Car
{
String clor;
String type;
//设置车的颜色和类型的构造方法
public Car(String clor,String type)
{
this.clor = clor;
this.type = type;
System.out.println("我是一辆"+clor+"的"+type+"轿车");
}
//车子的移动方法
public void movie ()
{
System.out.println("我启动了,开始走了 !");
}
//车子的停止方法
public void stop()
{
System.out.println("我歇火了,我停了");
}
public static void main(String[] args)
{
//生成一辆黑色别克轿车
Car car = new Car("黑色","别克");
//调用车子的movie方法,车子走了
car.movie();
//调用车子的stop方法,车子停了
car.stop();
System.out.println("我走了又停了");
}
}
编译运行结果如下:
package test;
public class Car{
public String color;//颜色
public String type;//类型
public void move(){
System.out.println("汽车走啦");
}
public void stop(){
System.out.println("汽车停止了");
}
public static void main(String[] args) {
Car car=new Car();
car.color="黑色";
car.type="别克";
car.move();
car.stop();
}
}
public class Car{
private String color;
private String type;
public Car(String color, String type){
this.color = color;
this.type = type;
}
public void move(){
system.out.println(color+type+"move");
}
public void stop(){
system.out.println(color+type+"stop");
}
public static void main(String[] args){
Car car = new Car("黑色","别克");
car.move();
car.stop();
}
}
有面有了,你看下吧,这是基础中的基础了
生成黑色的别克汽车? 什么意思 是打印出来吗? 如果用js倒是很好实现.