public class Dog {
private int weight;
public int getweight(){
return weight;
}
public void SetWeight(int newWeight){
if (newWeight > 0){
weight = newWeight;
}
}
}
public class TestDog {
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());
}
}
class dog is compiled but there is an error in class
TestDog when compiled and the error is with dot notations. I
want to kmow why there is error in testdog class when compiled.
Answer Posted / ashu chhabra
Thanks Aashish singh. You r right.My problem is solved
thankyou very much.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What can open a jar file?
What are the risks in java security? : java security
What is meant by framework in java?
What is exe file in java?
What is cdi in java?
Do I need jdk or jre?
Which class is the superclass of every class?
What is proxy object in java?
What is a controller in java?
How common are security breaches? : java security
How do I know if I have jre or jdk?
What is a bean class?
How do you run an executable jar file?
What is csrf in java?
If you’re overriding the method equals() of an object, which other method you might also consider?