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
If you’re overriding the method equals() of an object, which other method you might also consider?
What is the difference between the boolean & operator and the && operator?
What does jpa mean?
What is java ioc?
What is jep in java?
What are the types of cookies in java?
What is phantom memory?
What is spliterator in java se 8?
What is lambda expressions action func and predicate?
What is entitymanager in jpa?
Which interceptor is responsible for setting action javabean properties?
What is interceptor in java?
What is java persistence api used for?
Can java program run without jdk?
What is a service layer in java?