java编程错误
publicclasstelephone2{publicclassTelephone2{inta;//拨出号码intn;//拨打市内电话次数intl;//拨打长途次数do...
public class telephone2 {
public class Telephone2 {
int a ; //拨出号码
int n;//拨打市内电话次数
int l;//拨打长途次数
double left;//话费余额
}
class OrdinaryPhone extends Telephone2{
int month;//包月时长
double regularCost=20.0*month;//月租总开销
double cost=0.2*n+0.4*l+20.0*month;//包月外话费与月租之和
public void way1(){
if(left<cost){
left=left;
System.out.println("话费余额不足,欠费待缴"+"话费剩余是"+left);
}else{
left=left-cost;
System.out.println("扣费后话费余额为"+left);
}
}
}
class MobilePhone extends Telephone2{
double cost=l*0.4+n*0.4;
public void way2(){
if(left<cost){
left=left;
System.out.println("话费余额不足,欠费待缴"+"话费剩余是"+left);
}else{
left=left-cost;
System.out.println("扣费后话费余额为"+left);
}
}
}
public static void main(String[] args) {
OrdinaryPhone ordinary= new OrdinaryPhone();
MobilePhone mobile=new MobilePhone();
ordinary.n=10;
ordinary.l=10;
mobile.n=5;
mobile.l=15;
ordinary.way1();
mobile.way2();
System.out.println("OrdinaryPhone话费余额为"+ordinary.left);
System.out.println("MobilePhone话费余额为"+mobile.left);
}
}
运行结果显示Exception in thread "main" java.lang.Error: Unresolved compilation problem:
No enclosing instance of type telephone2 is accessible. Must qualify the allocation with an enclosing instance of type telephone2 (e.g. x.new A() where x is an instance of telephone2).
at telephone2.main(telephone2.java:40)
在System.out.println("OrdinaryPhone话费余额为"+ordinary.left);位置显示no enclosing type of telephone2 is accessiable
请问哪里有问题?谢谢 展开
public class Telephone2 {
int a ; //拨出号码
int n;//拨打市内电话次数
int l;//拨打长途次数
double left;//话费余额
}
class OrdinaryPhone extends Telephone2{
int month;//包月时长
double regularCost=20.0*month;//月租总开销
double cost=0.2*n+0.4*l+20.0*month;//包月外话费与月租之和
public void way1(){
if(left<cost){
left=left;
System.out.println("话费余额不足,欠费待缴"+"话费剩余是"+left);
}else{
left=left-cost;
System.out.println("扣费后话费余额为"+left);
}
}
}
class MobilePhone extends Telephone2{
double cost=l*0.4+n*0.4;
public void way2(){
if(left<cost){
left=left;
System.out.println("话费余额不足,欠费待缴"+"话费剩余是"+left);
}else{
left=left-cost;
System.out.println("扣费后话费余额为"+left);
}
}
}
public static void main(String[] args) {
OrdinaryPhone ordinary= new OrdinaryPhone();
MobilePhone mobile=new MobilePhone();
ordinary.n=10;
ordinary.l=10;
mobile.n=5;
mobile.l=15;
ordinary.way1();
mobile.way2();
System.out.println("OrdinaryPhone话费余额为"+ordinary.left);
System.out.println("MobilePhone话费余额为"+mobile.left);
}
}
运行结果显示Exception in thread "main" java.lang.Error: Unresolved compilation problem:
No enclosing instance of type telephone2 is accessible. Must qualify the allocation with an enclosing instance of type telephone2 (e.g. x.new A() where x is an instance of telephone2).
at telephone2.main(telephone2.java:40)
在System.out.println("OrdinaryPhone话费余额为"+ordinary.left);位置显示no enclosing type of telephone2 is accessiable
请问哪里有问题?谢谢 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询