内部类Dog.DogTestDrive中的非法静态声明

时间:2016-06-25 09:49:47

标签: java

内部类Dog.DogTestDrive中的非法静态声明

    class Dog{

int size;
String breed;
String name;

void bark()
{
System.out.println("Wuff! Wuff!");
}

public class DogTestDrive{

public static void main(String []args)
{
Dog d = new Dog();
d.size = 12;
d.name = "pongy";
d.bark();
d.breed = "Labrodor";
}
} 
}

修饰符'静态'只允许在常量变量声明中

1 个答案:

答案 0 :(得分:0)

改为代替public class DogTestDrive - > public static class DogTestDrive

class Dog {

    int size;
    String breed;
    String name;

    void bark()
    {
        System.out.println("Wuff! Wuff!");
    }

    public static class DogTestDrive {

        public static void main(String []args)
        {
            Dog d = new Dog();
            d.size = 12;
            d.name = "pongy";
            d.bark();
            d.breed = "Labrodor";
        }
    }
}