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 meant by annotations in java?
Which method is used to create the daemon thread?
What is an actionevent in java?
What is ibatis in java?
What is the java api?
What if the main method is declared as private?
What is factory pattern in java?
can a program use more than one command-line argument?
What is exe file in java?
Is openjdk the same as jdk?
What is the use of rs next () in java?
What is a java executable jar file?
What is data encapsulation?
Describe the principles of oops.
Which is better openjdk or oracle jdk?