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


Please Help Members By Posting Answers For Below Questions

What java systems libraries and methods are available for me to use?

456


What are anonymous methods and lambda expression?

436


What is java lang?

443


What is a cookie in java?

517


What do I need to install netbeans?

494






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

1437


What is the difference between map and flatmap in java?

486


What are jpa repositories?

484


What is interceptors in java?

489


When do we go for java 8 stream api? Why do we need to use java 8 stream api in our projects?

564


What is stateless in java?

500


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

1586


How do I install java re?

510


Can the main method be declared final?

531


What is a flatmap?

499