java编程求错,求改!!
首先编写一个抽象类,要求该类有如下3个抽象方法:publicabstractvoidf(intx);publicabstractvoidg(intx,inty);publ...
首先编写一个抽象类,要求该类有如下3个抽象方法:
public abstract void f(int x);
public abstract void g(int x,int y);
public abstract double h(double x);
然后分别给出该类的3个子类。要求:在应用程序的主类中使用这些子类创建对象,然后让他们的上转型对象调用方法:f(),g(),h()
abstract class A
{
public abstract void f(int x);
public abstract void g(int x,int y);
public abstract double h(double x);
}
class X extends A
{
public void f(int x)
{
System.out.println(x);
}
public void g(int x,int y)
{
System.out.println(x,y);
}
public double h(double x)
{
System.out.println(x);
}
}
class Y extends A
{
public void f(int x)
{
System.out.println(x);
}
public void g(int x,int y)
{
System.out.println(x,y);
}
public double h(double x)
{
System.out.println(x);
}
}
class Z extends A
{
public void f(int x)
{
System.out.println(x);
}
public void g(int x,int y)
{
System.out.println(x,y);
}
public double h(double x)
{
System.out.println(x);
}
}
public class P111_2
{
public static void main(String args[])
{
A a1;
a1=new X();
a1.f(10);
A a2;
a2=new Y();
a2.g(10,20);
A a3;
a3=new Z();
a3.h(10.0);
}
} 展开
public abstract void f(int x);
public abstract void g(int x,int y);
public abstract double h(double x);
然后分别给出该类的3个子类。要求:在应用程序的主类中使用这些子类创建对象,然后让他们的上转型对象调用方法:f(),g(),h()
abstract class A
{
public abstract void f(int x);
public abstract void g(int x,int y);
public abstract double h(double x);
}
class X extends A
{
public void f(int x)
{
System.out.println(x);
}
public void g(int x,int y)
{
System.out.println(x,y);
}
public double h(double x)
{
System.out.println(x);
}
}
class Y extends A
{
public void f(int x)
{
System.out.println(x);
}
public void g(int x,int y)
{
System.out.println(x,y);
}
public double h(double x)
{
System.out.println(x);
}
}
class Z extends A
{
public void f(int x)
{
System.out.println(x);
}
public void g(int x,int y)
{
System.out.println(x,y);
}
public double h(double x)
{
System.out.println(x);
}
}
public class P111_2
{
public static void main(String args[])
{
A a1;
a1=new X();
a1.f(10);
A a2;
a2=new Y();
a2.g(10,20);
A a3;
a3=new Z();
a3.h(10.0);
}
} 展开
展开全部
出错问题:1.System.out.println(x,y);错了 2.有些方法要返回值eg:return x;
修改后的代码:
abstract class A
{
public abstract void f(int x);
public abstract void g(int x,int y);
public abstract double h(double x);
}
class X extends A
{
public void f(int x)
{
System.out.println(x);
}
public void g(int x,int y)
{
System.out.println(x +" "+ y);
}
public double h(double x)
{
System.out.println(x);
return x;
}
}
class Y extends A
{
public void f(int x)
{
System.out.println(x);
}
public void g(int x,int y)
{
System.out.println(x +" "+ y);
}
public double h(double x)
{
System.out.println(x);
return x;
}
}
class Z extends A
{
public void f(int x)
{
System.out.println(x);
}
public void g(int x,int y)
{
System.out.println(x +" "+ y);
}
public double h(double x)
{
System.out.println(x);
return x;
}
}
public class P111_2
{
public static void main(String args[])
{
A a1;
a1=new X();
a1.f(10);
A a2;
a2=new Y();
a2.g(10,20);
A a3;
a3=new Z();
a3.h(10.0);
}
}
修改后的代码:
abstract class A
{
public abstract void f(int x);
public abstract void g(int x,int y);
public abstract double h(double x);
}
class X extends A
{
public void f(int x)
{
System.out.println(x);
}
public void g(int x,int y)
{
System.out.println(x +" "+ y);
}
public double h(double x)
{
System.out.println(x);
return x;
}
}
class Y extends A
{
public void f(int x)
{
System.out.println(x);
}
public void g(int x,int y)
{
System.out.println(x +" "+ y);
}
public double h(double x)
{
System.out.println(x);
return x;
}
}
class Z extends A
{
public void f(int x)
{
System.out.println(x);
}
public void g(int x,int y)
{
System.out.println(x +" "+ y);
}
public double h(double x)
{
System.out.println(x);
return x;
}
}
public class P111_2
{
public static void main(String args[])
{
A a1;
a1=new X();
a1.f(10);
A a2;
a2=new Y();
a2.g(10,20);
A a3;
a3=new Z();
a3.h(10.0);
}
}
展开全部
额,你不是已经给出实现代码了嘛
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
没太明白你的意思,你程序写错了?,这句话是什么意思:然后让他们的上转型对象调用方法:f(),g(),h()
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你的system.out.println()出错了,这个方法只能有一个String参数,而你写的其中有两个,所以错了,你改成一个参数就行了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询