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 / madan
This piece of code will not generate an error surely even
with the dot notations. if you got errors post the
description of that error here
| Is This Answer Correct ? | 2 Yes | 1 No |
Post New Answer View All Answers
How do I enable java in google chrome?
Where is java installed?
How do I create an executable jar file?
What is java lang noclassdeffounderror?
Which is more secure: java or activex? : java security
What are java’s rules regarding tabs, spaces and newline characters?
What is phantom memory?
What is stateless object in java?
What is flatmap java?
What is a java executable jar file?
Is jpa a framework?
Why is lambda expression used?
Why do we need new date and time api in java se 8?
how can we create the ui using netbeans,having the code?
What is ehcache in java?