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.
Answers were Sorted based on User's Feedback
Answer / 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 |
Answer / madan
This piece of code will not generate an error surely even
with the dot notations. if you got errors post the
description of that error here
| Is This Answer Correct ? | 2 Yes | 1 No |
Answer / ashu chhabra
Thanks Aashish singh. You r right.My problem is solved
thankyou very much.
| Is This Answer Correct ? | 0 Yes | 0 No |
Java prints out a ton of digits when I system.out.println() a double. How can I format it so it displays only 3 digits after the decimal place?
What is web xml java?
What type of parameter passing does java support?
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
What is a jvm?
What are the rules regarding quotation marks?
Explain the common use of ejb?
What's the difference between authentication and authorization? : java security
In hibernate what is the difference between the Session and SessionFactory?
What is log4j in java?
I am trying to create a new universal user group. Why can't i? : java security
Why dependency injection is used in java?