0
Eclipse说在下面的代码中关键字“new”和“dog”有错误,但我直接从书中复制了这个示例。我不知道什么是错在这里在Eclipse中的类中创建新对象时遇到问题
Eclipse的错误#1:狗不能被解析为一个变量 错误#2:语法错误令牌“新”,删除此令牌
package pkg;
// creating the Dog class
class Dog {
int size;
String breed;
String name;
void bark(){
System.out.println("Ruff! Ruff!");
}
}
// this function does the testDrive
public class HelloWorld {
public static void main(String[] args) {
// problem occurs here, both "new" and "dog" underlined
Dog d = new Dog;
d.size = 40;
d.bark();
}
}
它的工作原理!!!!谢谢 – user133466
没问题,很高兴帮助。 –