java基础_类和对象.—5
首先,编写一个类ChongZai,该类中有3个重载的方法void print();其次,
再编写一个主类来测试ChongZai类的功能。
public class Chongzai1 { // 首先,编写一个类ChongZai,该类中有3个重载的方法void print();其次, // 再编写一个主类来测试ChongZai类的功能。 int a,b,c; public int getA() { return a; } public void setA(int a) { this.a = a; } public int getB() { return b; } public void setB(int b) { this.b = b; } public int getC() { return c; } public void setC(int c) { this.c = c; } public double add (double a,double b) { return(a+b); } public double add (double a,double b,double c) { return (add(a, b)+c); } public double ji(double a,double b) { return a*b; } public double ji(double a,double b,double c) { return ji(a,b)*c; } public double h(double a,double b,double c) { return ji(a,b)+c; } public static void main(String [] args) { Chongzai1 c=new Chongzai1(); System.out.println(c.add( 3, 4)); System.out.println(c.add(3, 4, 5)); System.out.println(c.ji(3, 4)); System.out.println(c.ji(3, 4, 5)); System.out.println(c.h(3, 4, 5)); } }