Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Why do we need new date and time api in java se 8?

830


Topic- looping,function overloading,nesting ,polymorphism. Aim - to write a function with a name buzz-buds,that will check whether the given numbers are buddies or not on the basis of no. of parameters passed during function calling.

2005


What does persist mean in java?

920


What is java ioc?

817


What is persistence xml in java?

828


Is jar an executable?

811


Explain suspend() method under thread class>

975


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

1806


What is dto layer in java?

816


How do javabeans work?

825


What is a jvm?

892


What is ehcache in java?

904


How do I enable java in google chrome?

957


What is serializable in java?

788


What are the advantages of java 8’s date and time api over old date api and joda time api?

1000