public class TextDog {
public static void main(String[] args) {
Dog d = new Dog();
System.out.println("Dog d's weight is "
+ d.getWeight());
d.setWeight(42);
System.out.println("Dog d's weight is "
+ d.getWeight());
d.setWeight(-42);
System.out.println("Dog d's weight is "
+ d.getWeight());
}
}
Dog d = new Dog(); JAVAC的时候显示 找不到符号 可是我输入和书上得的一样哦
public static void main(String[] args) {
Dog d = new Dog();
System.out.println("Dog d's weight is "
+ d.getWeight());
d.setWeight(42);
System.out.println("Dog d's weight is "
+ d.getWeight());
d.setWeight(-42);
System.out.println("Dog d's weight is "
+ d.getWeight());
}
}
Dog d = new Dog(); JAVAC的时候显示 找不到符号 可是我输入和书上得的一样哦
也许这个例子是在前面例子的基础上改的呢?看看书上前面点有没有Dog类的例子吧....
public static void main(String[] args) {
Dog d = new Dog();
System.out.println("Dog d's weight is "
+ d.getWeight());
d.setWeight(42);
System.out.println("Dog d's weight is "
+ d.getWeight());
d.setWeight(-42);
System.out.println("Dog d's weight is "
+ d.getWeight());
}
}
Dog d = new Dog(); JAVAC的时候显示 找不到符号 可是我输入和书上得的一样哦请问,java加载时如何认知Dog这东西,显然,你没有引入或者说没有告诉java编译器如何解译这个Dog所以是错的
书上前面还有一个代码
public class Dog{
private int weight;
public int getWeight(){
return weight;
}
public void setWight(int newWeight) {
if ( newWeight >0) {
weight = newWeight;
}
}
}
书上前面还有一个代码
public class Dog{
private int weight;
public int getWeight(){
return weight;
}
public void setWight(int newWeight) {
if ( newWeight > 0) {
weight = newWeight;
}
}
}
==============================================================
这不就完了嘛,你把Dog类先javac了,在去javac 你的TextDog类.
顺便问下 明天早上8点到9点 有没有人在 我有个测试要出道题 我放上来 大家帮我看下
if ( newWeight > 0) {
weight = newWeight;
你少打了一个字母e