Java说白了就是一门语言,像我们平时学校里学的英语,或者其他外语一样,是和其他人交流的工具,让别人知道你要表达什么,只不过Java语言是面向计算机的,人与机器交流,让计算机懂得我们所要表达的,从而让计算机运行出我们想要的结果。
java是什么东西
public class Geometry {public Geometry(int w, int h) {
width = w
height = h
}
public int area() {
return width * height
}
private int width, height
}
public class Cube extends Geometry {
public Cube(int w, int h) {
super(w, h)
}
public Cube(int a, int b, int c) {
super(a, b)
height = c
}
public void setHeight(int h) {
height = h
}
public int volumn() {
return area() * height
}
private int height
}
public class User {
public static void main(String []args) {
Cube cube1 = new Cube(1,2,3)
Cube cube2 = new Cube(4, 5)
cube2.setHeight((int) (Math.random() * 10) + 1)//avoid zero height
System.out.println("Cube 1 area: " + cube1.area() + " volumn: " + cube1.volumn())
System.out.println("Cube 2 area: " + cube2.area() + " volumn: " + cube2.volumn())
}
}