interface dongzuo
{
     void run();
     void fly();
}
/*interface flyer
{
     void fly();
}*/
interface brid extends dongzuo
{
    void jump();
}
class person implements brid
{  //public static final int x=10;
/*public person ( int x)
{
 this.x=x;
}*/
 public  void run()
   {
    System.out.println(x);
   }
 public  void fly()
   {
   }
 public void jump()
 {
 }
}
public static void  main(String[] args)
{
    person x = new person();
           x =10; 
           x.run();
  
    
}如我要打印出X  那mian里面要怎么写。 大侠们指点指点

解决方案 »

  1.   

    person x = new person(10);
    构造方法也别注释掉
    输出结果就是10了
      

  2.   

    其实楼主的代码已经可以了
    实际上person实现了brid间接实现了dongzuo
    然后在person中实现了run方法
    直接在main中调用就可以了...
    class person implements brid

     public static final int x=10;
        
     public  void run()
       {
           System.out.println(x);
       }
     public  void fly()
       {
       }
     public void jump()
         {
         } public static void  main(String[] args)
    {
        person p = new person();
               p.run();
      
        
    }}
      

  3.   

    实例化就是上面new person()
    然后这个对象包含了初始化的字段
    也可以通过set给改变字段数值
    在通过get出来
    就可以拿到了结果
    你就可以处理了
      

  4.   


    class person implements brid{
    private int x;
    public int get(){
    return x;
    }
    public void set(int x){
    this.x=x;
    }
    }
    public static void  main(String[] args)
    {
        person x = new person();
               x.set(1);
    System.out.println(x.get());
      
        
    }
    //朋友,先写个helloworld好了
    还是字段和方法的用处
      

  5.   

    interface dongzuo
    {
         void run();
         //void fly();
    }
    /*interface flyer
    {
         void fly();
    }*/
    interface brid extends dongzuo
    {
        void jump();
    }
    public class person implements brid
    {  int x=0;
        public person ( int x)
        {
             this.x=x;
        }
     public  void run()
       {
           System.out.println(x);
       }
     //public  void fly()
      // {
      // }
     public void jump()
         {
         }public static void  main(String[] args)
    {
    person p = new person(10);
               
               p.run();
      
        
    }
    }
    调试通过,打印出10~
    文件名保存为people.java
    或者Eclipse下新建项目→项目名:people→完成→新建类→名称为people→把上面代码复制上
    →结果打印10~
      

  6.   

    建议用Eclipse···呵呵~有什么错误就直接显示出来的,对了,最好是中文版的~
      

  7.   

    菜鸟在这接问一句,莫怪:接口不是没有实现的东西,那api中的接口功能是怎么来的
      

  8.   

      去掉 main 方法里面的
      x=10
    改为:
      Person x = new person();
      x.run(10);另外:public void run(int x)
       {
           System.out.println(x);
       }