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 / aashish singh
just check the case some where you've used upper case where as
somewhere it is lower case. . . .
i modified your code followin is the correct workin code withoput any errors
====================================================
class Dog {
private int weight;
public int getWeight(){
return weight;
}
public void setWeight(int newWeight){
if (newWeight > 0){
weight = newWeight;
}
}
}
public class TestDog {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
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());
}
}
| Is This Answer Correct ? | 7 Yes | 0 No |
Post New Answer View All Answers
Is jar an executable?
What are messages in java?
Can you compile java into exe?
What is lambda expressions action func and predicate?
What is cdi bean in java?
How do you count in java?
What is the use of flatmap?
Why doesn't lsdou work under windows nt? : java security
What is ibatis in java?
What is phantom memory?
What is difference between loosely coupled and tightly coupled in java?
What is an entity in java?
what are the different phases in delivering the project during development and maintenance?
What is transient in java?
What is scrollable resultset in java?