Java类方法的简单使用

来源:互联网 发布:单片机延时1s程序汇编 编辑:程序博客网 时间:2024/06/09 22:57

源程序:

import java.util.*;


public class Example2_4 {
public static void main(String args[]){
double max=Computer.max(12,45);

System.out.println(max);
}
}


class Computer{
static double max(double a,double b){
if (a>b)
return a;

else
return b;
}
}


程序截图



补充:

class Tra{
float sideA,sideB,sideC;
static int count;

void setSide(float sideA,float sideB,float sideC){
this.sideA=sideA;  //this表示当前对象
this.sideB=sideB;
this.sideC=sideC;
}

static void setCount(int count){
Tra.count=count;   //Tra.count表示所有对象共享的类变量
}
}

0 0
原创粉丝点击