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
What is lambda used for?
How can I swap two variables without using a third variable?
How do I install java re?
What are the types of cookies in java?
How do I open my java console?
What is a static method?
What is phantom memory?
Does netbeans need jdk?
What is the difference between the boolean & operator and the && operator?
Is it better to learn java or python?
What is the difference between Logical Parallelism and Physical Parallelism?
What is entitymanager in java?
What is the most important feature of java?
What is java api?
What is lambda expressions action func and predicate?