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



public class Dog { private int weight; public int getweight(){ return weight; } public void Set..

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

public class Dog { private int weight; public int getweight(){ return weight; } public void Set..

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

public class Dog { private int weight; public int getweight(){ return weight; } public void Set..

Answer / ashu chhabra

Thanks Aashish singh. You r right.My problem is solved
thankyou very much.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Java Related AllOther Interview Questions

I want to control database connections in my program and want that only one thread should be able to make database connection at a time. Define how can I implement this logic?

0 Answers  


What is contextpath in java?

0 Answers  


Is eclipse a jdk?

0 Answers  


What is custom tag in java?

0 Answers  


What are orm tools in java?

0 Answers  






i have make jar file but when i click in this file then arr swhow "no faund main class" plese help me in this problem becose i want to make a jar file as a dxdcutable file

1 Answers  


What is a delimiter in java?

0 Answers  


Is java built on c?

0 Answers  


suppose we have one String s="india is my country"; now we get the o/p "like country my is India". what is the logic?

2 Answers  


What is lambda value?

0 Answers  


Who is at risk in java? : java security

0 Answers  


Why oracle type 4 driver is named as oracle thin driver?

0 Answers  


Categories