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 do we need new date and time api in java se 8?
How can I protect myself? : java security
What is a static method?
What about products that claim to detect malicious applets? : java security
Is it better to learn java or python?
What is a uint8?
can anyone tell me what kind of questions are asked for core java exam in aptech
In java thread programming, which method is a must implementation for all threads?
What are messages in java?
Is java an api?
What is flatmap in java8?
What is meant by framework in java?
Explain daemon thread.
Which class is the superclass of every class?
What is class forname java?