请问在一个Java类中的多个方法之间。一个方法体中能否直接调用另外一个方法的功能去实现它的本身功能吗?

解决方案 »

  1.   

    这个 当然没有 问题了
    class  Test{public void run(){}public void go(){}public void method{
        run();
        go();
    }}
      

  2.   

    可以,以构造方法为例:public class A
    {
      private String a;
      private String b;  public A(String a)
     {
        this(a,null);
      }  public A(String a,String b)
      {
        this.a=a;
        this.b=b;
       }
    }
      

  3.   

    可以
    class Test
    {
    private String name;
    private int age;
    public Test(String name,int age)
    {
    this.name=name;
    this.age=age;
    }
    void myName()
    {
    System.out.println("My name is "+name+".");
    }
    void myAge()
    {
    System.out.println("My age is"+ age+"years.");
    }
    void selfShow()
    {
    System.out.println("Hello everyone!");
    myName();//直接调用另外一个方法的功能去实现它的本身功能
    myAge();
    }
    }
    class ClassTest
    {
    public static void main(String [] args)
    {
    Test t=new Test("Tom",25);
    t.selfShow();
    }
    }
      

  4.   

     go  ,go ,go