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
Why do we need new date and time api in java se 8?
Topic- looping,function overloading,nesting ,polymorphism. Aim - to write a function with a name buzz-buds,that will check whether the given numbers are buddies or not on the basis of no. of parameters passed during function calling.
What does persist mean in java?
What is java ioc?
What is persistence xml in java?
Is jar an executable?
Explain suspend() method under thread class>
when i send the request to the JSP page it will print as it is and why? and how to solve this problem please inform me that solution
What is dto layer in java?
How do javabeans work?
What is a jvm?
What is ehcache in java?
How do I enable java in google chrome?
What is serializable in java?
What are the advantages of java 8’s date and time api over old date api and joda time api?