问答详情
源自:8-3 如何使用 Java 中的对象

主类怎么加进去啊,代码错了不会改

public class dog { int age =5; String name="乐乐"; String color="白色"; int weight =10; String sex="female"; void eat() { } void look() { } void yao() { } void run() { } void swim() { } {System.out.println("beef"); System.out.println("person"); System.out.println("旺旺~~~~~"); System.out.println("quick"); System.out.println("会"); } public class dog1 extends dog {public dog1(){ super(); }    public class dog2 extends dog    {public dog2(){    this();        }    }
    public static void main (String args[]) { dog dog=new dog(); System.out.println("姓名:"+dog.name); System.out.println("年龄:"+dog.age); System.out.println("颜色:"+dog.color); System.out.println("体重:"+dog.weight); System.out.println("性别:"+dog.sex); dog.eat(); dog.look(); dog.yao(); dog.run(); dog.swim();}

提问者:cute倩影O_o 2016-10-09 17:25

个回答

  • 終結丶天涯
    2016-10-09 18:41:19
    已采纳

    public class Dog {	
    	int age =5;	
    	String name="乐乐";	
    	String color="白色";	
    	int weight =10;	
    	String sex="female";	
    	void eat()	{	}	
    	void look()	{	}	
    	void yao()	{	}	
    	void run()	{	}	
    	void swim()	{	}	
    	{
    		System.out.println("beef");	
    		System.out.println("person");	
    		System.out.println("旺旺~~~~~");	
    		System.out.println("quick");	
    		System.out.println("会");	
    	}	
        class dog1 extends Dog{public dog1(){	super();  } }    
        class dog2 extends Dog{public dog2(){   super();  } } 
        public static void main(String args[]){	
    		Dog dog=new Dog();	
    		System.out.println("姓名:"+dog.name);	
    		System.out.println("年龄:"+dog.age);	
    		System.out.println("颜色:"+dog.color);	
    		System.out.println("体重:"+dog.weight);	
    		System.out.println("性别:"+dog.sex);	
    		dog.eat();	
    		dog.look();	
    		dog.yao();	
    		dog.run();	
    		dog.swim();
        }
    }


  • 慕粉1900176943
    2017-02-17 11:43:57

    public class Test {

    int age =5;

    String name="乐乐";

    String color="白色";

    int weight =10;

    String sex="female";

    void eat() {

    System.out.println("beef");

    }

    void look() {

    System.out.println("person");

    }

    void yao() {

    System.out.println("旺旺~~~~~");

    }

    void run() {

    System.out.println("quick");

    }

    void swim() {

    System.out.println("会");

    }

    public class dog1 extends Test {

    public dog1(){ super();  

    }

    }

    public class dog2 extends Test    {

    public dog2(){

    super();       

    }    

    public static void main (String args[]) {

    Test dog=new Test();

    System.out.println("姓名:"+dog.name);

    System.out.println("年龄:"+dog.age);

    System.out.println("颜色:"+dog.color);

    System.out.println("体重:"+dog.weight);

    System.out.println("性别:"+dog.sex);

    dog.eat();  

    dog.look();  

    dog.yao();  

    dog.run();  

    dog.swim();

    }

    }


  • 終結丶天涯
    2016-10-09 18:34:50

    不要在同一个java文件里写好几个类,public class一个类中只能出现一次。还有你括号丢了很多啊。主类就是main方法所在的类。你最后丢了个括号,只剩下方法,当然没类了。

  • vellid
    2016-10-09 18:30:34

    同一个文件里,只能有一个类为public,另定义的另两个子类,不能加public。


    public class Dog {
        public static void main(String args[]) {
            Dog dog = new Dog();
            System.out.println("姓名:" + dog.name);
            System.out.println("年龄:" + dog.age);
            System.out.println("颜色:" + dog.color);
            System.out.println("体重:" + dog.weight);
            System.out.println("性别:" + dog.sex);
            dog.eat();
            dog.look();
            dog.yao();
            dog.run();
            dog.swim();
        }

        int age = 5;
        String name = "乐乐";
        String color = "白色";
        int weight = 10;
        String sex = "female";

        void eat() {
        }

        void look() {
        }

        void yao() {
        }

        void run() {
        }

        void swim() {
        }

        {
            System.out.println("beef");
            System.out.println("person");
            System.out.println("旺旺~~~~~");
            System.out.println("quick");
            System.out.println("会");
        }

        class dog1 extends Dog {
            public dog1() {
                super();
            }

            class dog2 extends Dog {
                public dog2() {
                    super();
                }
            }
        }
    }

  • 慕妹6786642
    2016-10-09 18:27:09

    dog2 继承还是用super()啊,你怎么用的this