极其伤脑筋的问题 那位好心人帮忙看一下 急急急!在线等待!
// X.java
package X;
public class X{
int a,b;
public X(){}
public void setab(int a,int b){
this.a=a;
this.b=b;
}
public void print(){
int s;
s=a*b;
System.out.println( "s= "+s);
}
}
//Y.java
package X.Y;
public class Y{
public Y(){}
int a,b;
public void setab(int a,int b){
this.a=a;
this.b=b;
}
public void print(){
int sum;
sum=a+b;
System.out.println( "sum= "+sum);
}
}
//Exam3_24.java
import X.*;
import X.Y.*;
class C extends X{
int c,v;
}
public class Exam3_24{
public static void main(String args[]){
X x=new X();
x.setab(4,6);
x.print();
Y y=new Y();
y.setab(3,5);
y.print();
C c=new C();
c.setab(4,9);
c.print();
}
}
为何
import X.*;
import X.Y.*;时不能通过?
而import X.X;
import X.Y.Y;
时能通过?
------解决方案--------------------不要把package name和class name用同样的名字
一般建议package name用小写
class name首字母大写
------解决方案--------------------测试
import X.*;
import X.Y.*;
可以通过啊