Topic: 请大家帮我看下这个关于接口的问题!!

  Print this page

1.请大家帮我看下这个关于接口的问题!! Copy to clipboard
Posted by: fc6029585
Posted on: 2007-04-21 23:25

我的目的是..创建一个接口。分别求这2个数的平方和立方。
创建2个类。实现接口。一个类返回平方,一个类返回立方。
我编译到这里编不走了,因为有错。。
请帮我看看

interface jiekou{
void f1();
}

class number1 implements jiekou{
double x1,y1;
number1(double u,double v){x=u;y=v;}
public void f1(){System.out.println(x+"平方的值是"+x*x);
System.out.println(y+"平方的值是"+y*y);
}
}


class number2 implements jiekou{
double x2,y2;
number2(double u1,double u2){x2=u2;y2=v2;}
public void f1(){System.out.println(x+"立方的值是"+x*x*x);
System.out.println(y+"立方的值是"+y*y*y);
}
}

public class A_1_2_3_4{
public static void main(Sting []args){
number1 pr1=new number1(2.0,3.0);
number2 lf2=new number2(2.0,3.0);
jiekou jiekouSet[]={pf1,lf2};
for(int i=0;i<jiekouSet.length;i++)
jiekouSet[i].f1();
}
}

2.Re:请大家帮我看下这个关于接口的问题!! [Re: fc6029585] Copy to clipboard
Posted by: fc6029585
Posted on: 2007-04-21 23:27

错了~~~应该是这个~~上面有错。。
interface jiekou{
void f1();
}

class number1 implements jiekou{
double x1,y1;
number1(double u1,double v1){x1=u1;y1=v1;}
public void f1(){System.out.println(x+"平方的值是"+x*x);
System.out.println(y+"平方的值是"+y*y);
}
}


class number2 implements jiekou{
double x2,y2;
number2(double u1,double v2){x2=u2;y2=v2;}
public void f1(){System.out.println(x+"立方的值是"+x*x*x);
System.out.println(y+"立方的值是"+y*y*y);
}
}
public class A_1_2_3_4{
public static void main(Sting []args){
number1 pf1=new number1(2.0,3.0);
number2 lf2=new number2(2.0,3.0);
jiekou jiekouSet[]={pf1,lf2};
for(int i=0;i<jiekouSet.length;i++)
jiekouSet[i].f1();
}
}

3.Re:请大家帮我看下这个关于接口的问题!! [Re: fc6029585] Copy to clipboard
Posted by: fc6029585
Posted on: 2007-04-21 23:29

晕了~~真是不小心。。还是有错。因该是这个
interface jiekou{
void f1();
}

class number1 implements jiekou{
double x1,y1;
number1(double u1,double v1){x1=u1;y1=v1;}
public void f1(){System.out.println(x+"平方的值是"+x*x);
System.out.println(y+"平方的值是"+y*y);
}
}


class number2 implements jiekou{
double x2,y2;
number2(double u1,double v2){x2=u2;y2=v2;}
public void f1(){System.out.println(x+"立方的值是"+x*x*x);
System.out.println(y+"立方的值是"+y*y*y);
}
}
public class A_1_2_3_4{
public static void main(Sting []args){
number1 pf1=new number1(2.0,3.0);
number2 lf2=new number2(2.0,3.0);
jiekou jiekouSet[]={pf1,lf2};
for(int i=0;i<jiekouSet.length;i++)
jiekouSet[i].f1();
}
}

4.Re:请大家帮我看下这个关于接口的问题!! [Re: fc6029585] Copy to clipboard
Posted by: JiafanZhou
Posted on: 2007-04-22 05:55

Compilation error should be solved all by yourself !! what information does your compiler tell you? Fix it.

5.Re:请大家帮我看下这个关于接口的问题!! [Re: fc6029585] Copy to clipboard
Posted by: aaarong
Posted on: 2007-04-22 08:51

interface jiekou{
void f1();
}

class number1 implements jiekou{
double x1,y1;
number1(double u1,double v1){x1=u1;y1=v1;}
public void f1(){System.out.println(x1+"平方的值是"+x1*x1);
System.out.println(y1+"平方的值是"+y1*y1);
}
}

class number2 implements jiekou{
double x2,y2;
number2(double u1,double v2){x2=u1;y2=v2;}
public void f1(){System.out.println(x2+"立方的值是"+x2*x2*x2);
System.out.println(y2+"立方的值是"+y2*y2*y2);
}
}
public class A_1_2_3_4{
public static void main(String []args){
number1 pf1=new number1(2.0,3.0);
number2 lf2=new number2(2.0,3.0);
jiekou jiekouSet[]={pf1,lf2};
for(int i=0;i<jiekouSet.length;i++)
jiekouSet[i].f1();
}
}
给你点意见:
> 做为一名程序员, 独立思考,善于专研是最基本的品质
加油.......


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923