public class Car {
private String color; // 定义汽车颜色,全局变量
private int numLuntai; // 定义汽车轮胎数,全局变量
public Car(String color, int numLuntai){
super();
this.color = color;
this.numLuntai = numLuntai;
}
public void run() {
System.out.println(this.numLuntai+ "个轮子的" +this.color + "轿车在马路上行驶着");
}
}
public class ClassTest {
public static void main(String[] args){
Car bmw = new Car("黑色", 4); // 创建一个轿车对象,名字为bmw
bmw.run();
}
}
publicclass Car {
private String color; // 定义汽车颜色,全局变量
private int numLuntai; // 定义汽车轮胎数,全局变量
public Car(String color, int numLuntai){
super();
this.color = color;
this.numLuntai = numLuntai;
}
public void run() {
String carName=”宝马牌”; //这个就是局部变量
System.out.println(this.numLuntai+ "个轮子的" +this.color + carName+"轿车在马路上行驶着");
}
}
publicclass ClassTest {
public static void main(String[] args){
Car bmw = new Car("黑色", 4); // 创建一个轿车对象,名字为bmw
bmw.run();
}
}
public class Person {
private int age=1000;//定义成员变量,年龄为1000
public void setAge(int age) {
age=age;
System.out.println("方法内的年龄"+age);
}
public void sayHello() {
System.out.println("我的年龄是"+age+".");
}
}
Person p=new Person(); p.setAge(20); p.sayHello();
//方法内的年龄20 //我的年龄是1000.
public class Person {
private int age=1000;
public void setAge(int age) {
this.age=age;
System.out.println("方法内的年龄"+age);
}
public void sayHello() {
System.out.println("我的年龄是"+age+".");
}
}
//方法内的年龄20 //我的年龄是20.
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有