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
What is phantom memory?
What is the purpose of jdk?
What is jdk jre and jvm?
Do I really have to type in the programs in the book to try them out?
What is entitymanager in java?
Who created eclipse?
What is a cookie in java?
What is an interceptor in java?
What is explicit casting?
What is the use of lambda functions?
Write a program using call by refernce for two different classes to explain to print whether a given number is automorphic or not.
What is @qualifier in java?
Do I need jdk or jre?
Why is javac not recognized?
What is the use of flatmap in java 8?