Initial commit

This commit is contained in:
2025-11-06 10:29:13 +08:00
commit 0becd14830
318 changed files with 7145 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
package com.ex4;
public class Sobject {
private String name;
private double weight; //ÖØÁ¿
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getWeight() {
return weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
public Sobject(String name, double weight) {
this.name = name;
this.weight = weight;
}
public void print() {
System.out.println("name:"+name+",weight:"+weight);
}
}

View File

@@ -0,0 +1,28 @@
package com.ex4;
public class Table extends Sobject{
private double width; //宽度
private double length; //长度
private double height; //高度
//如果该类不写构造方法,系统会自动为 Table添加一个无参数的构造方法
//在这个无参构造方法中会自动调用Sobject类中的无参数的构造方法
// public Table() {
// super();
//// super("abc",34.5);
// }
//
public Table(String name,double weight,double width,double length,double height) {
super(name, weight);
this.width=width;
this.length=length;
this.height=height;
}
public double area() {
return width*length;
}
public void changeWeight(double w) {
setWeight(w);
}
}

View File

@@ -0,0 +1,15 @@
package com.ex4;
public class Test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Table table=new Table("A1", 23, 1.8, 2.3, 0.8);
double area=table.area();
table.changeWeight(45);
System.out.println(area);
System.out.println(table.getWeight());
}
}