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 / ashu chhabra
Thanks Aashish singh. You r right.My problem is solved
thankyou very much.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
In java thread programming, which method is a must implementation for all threads?
How long can a lambda function run?
What is the use of flatmap in java 8?
Can the main method be declared final?
What is gwt in java?
How can the static main method use instance variables?
Spring framework ---Can somebody explain me in easily understandable format about AOP, IOC and DI, so that i can explain in interview rather than just telling what is available in net. I am not able to understand that also. I am new to Spring
Differences between intermediate operations and terminal operations of java 8’s stream api?
What is tier in java?
Why we use beans in java?
What is reflection in java?
What is lsdou? : java security
Name primitive java types.
What is the difference between a jvm and a jdk?
What is static class in java?