Topic: [求助]关于返回值类型

  Print this page

1.[求助]关于返回值类型 Copy to clipboard
Posted by: 火山一角
Posted on: 2005-10-12 16:59

以下是我编的一个程序,运行显示第25行有误,错误如下:
invalid method declaration;return type required.我该怎么修改呢?另外我想问一下,JAVA中到底有哪几种数据类型.如果是复合类型的话,那么该返回什么类型的数据.程序代码如下:
class Point
{
  int x,y;
  String name="a point";
  Point()
  {
    x=0;y=0;
  }
  Point(int x,int y,String name)
  {
    this.x=x;this.y=y;this.name=name;
  }
  int getX()
  {
    return x;
  }
  int getY()
  {
    return y;
  }
  void move(int newX,int newY)
  {
    x=newX;y=newY;
  }
   newPoint(String name);
  {
   Point newP=new Point(-x,-y,name);
   return newP;
  }
  boolean equal(int x,int y)
  {
    if(this.x==x&&this.y==y) return true;
    else return false;
  }
  void print()
  {
    System.out.println(name+": x="+x+" y="+y);
  }
}
public class UsingObject
{
  public static void main(String[] args)
  {
    Point p=new Point();
    p.print();
    p.move(50,50);
   System.out.println("****after moving****");
   System.out.println("get x and y directly");
   System.out.println("x="+p.x+" y="+p.y);
   System.out.println("or get x and y by calling method");
   System.out.println("x="+p.getX()+" y="+p.getY());
   if(p.equal(50,50)) System.out.println("I like this point!");
   else System.out.println("I hate it!");
   p.newPoint("a new point").print();
   Point q=new Point(10,15,"another new point");
   q.print();
  }
}谢谢各位高手的帮忙.

2.Re:[求助]关于返回值类型 [Re: 火山一角] Copy to clipboard
Posted by: bluecrystal
Posted on: 2005-10-12 17:18

先不说你的代码的其他问题
仅仅针对你的代码而言
第25行尾的;去掉
然后方法前面加上Point

3.Re:[求助]关于返回值类型 [Re: 火山一角] Copy to clipboard
Posted by: wnhoo
Posted on: 2005-10-17 12:18

................
  //你这儿有问题,修改一下即可
  Point newPoint(String name){
    Point newP = new Point(-x, -y, name);
    return newP;
  }
................................


   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