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 java systems libraries and methods are available for me to use?
What are anonymous methods and lambda expression?
What is java lang?
What is a cookie in java?
What do I need to install netbeans?
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 the difference between map and flatmap in java?
What are jpa repositories?
What is interceptors in java?
When do we go for java 8 stream api? Why do we need to use java 8 stream api in our projects?
What is stateless in java?
Spring framework ---Can somebody explain me in easily understandable format about AOP, IOC and DI, so that i can explain in interview rather than just telling what is available in net. I am not able to understand that also. I am new to Spring
How do I install java re?
Can the main method be declared final?
What is a flatmap?