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
Why there are no global variables in java?
How do I find jre version?
Why is javac not recognized?
What is the first argument of the string array in main method?
What are the authentication modes in asp.net? : java security
How do you create a jar file?
What is phantom memory?
Explain working of java virtual machine (jvm)?
What are tags in java?
Is java a framework?
How common are security breaches? : java security
How do I install jdk?
What is spliterator in java se 8?
What is web container in java?
How do I install eclipse?