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 should I format my code? How should I comment my code?
What is flatmap in java8?
What do you understand by casting in java language? What are the types of casting?
Explain the encapsulation principle.
Can I have multiple main methods in the same class?
What is the difference between the boolean & operator and the && operator?
Which version of my browser should I use? : java security
Is php faster than java?
What is numberformatexception in java?
Can the main method be overloaded?
What is meant by framework in java?
What is type inference? Is type inference available in older versions like java 7 and before 7 or it is available only in java se 8?
Can we extract main method from another class?
What is mime in java?
What is an entity in java?