java小程序哪里不对?

来源:百度知道 编辑:UC知道 时间:2024/06/23 04:46:51
class Test
{
void max(int a,int b){
this.a=a;
this.b=b;
System.out.println(a>b?a:b);
}
void max(float a,float b){
this.a=a;
this.b=b;
System.out.println(a>b?a:b);
}
}
public class Testtest{
public static void main(String[] args){
Test t1=new Test(int 5,int 7);
Test t2=new Test(float 12.5,float 7.8);
t1.max();
t2.max();
}
}

class Test
{
//少了一行数据项a和b的定义
private Object a,b;
void max(int a,int b){
this.a=a;
this.b=b;
System.out.println(a>b?a:b);
}
void max(float a,float b){
this.a=a;
this.b=b;
System.out.println(a>b?a:b);
}
}
public class Testtest{
public static void main(String[] args){

//没有定义Test(int,int)这个构造函数,所以这里调用默认的函数

Test t1=new Test();
Test t2=new Test();
t1.max(5,7);
t2.max(12.5f,7.8f);
}
}

class Test1
{
int a,b;
float c,d;
Test1(int a,int b){
this.a=a;
this.b=b;
}

Test1(float c, float d) {
this.c=c;
this.d=d;
}

void maxInt(){
System.out.println(a>b?a:b);
}
void maxFloat(){
System.out.println(c>d?c:d);
}
}
public class Testtest{
public static void main(String[] args){
Test1 t1=new Test1(5,7);
Test1 t2=new Test1(