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
What is stateful in java?
For each of the following program segments,give a big zero
analysis for the running time
1.For (i=0;i What is the difference between lambda expression and anonymous methods? Is java an api? What happens when the parent process of a child process exits before the child ? Which version of jdk is required for netbeans 8.0 2? What is the meaning of the words public, static and void? i have client interview in TCS.client is CITI BANK.how to
face it,what type of questions they will ask,please tell
send me to kumar525job@gmail.com Explain issues of old java date api? What is java aop? What is the resourcebundle class? What is the use of flatmap in java 8? What are struts java? What is resultsetmetadata in java? Please can anybody explain what exactly "the project
architecture" means???