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.

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

Which is the Best institute to do academic Project in Java? Need information about institutes at Ameerpet, Hyderabad.

8 Answers  


What is interceptor in java?

0 Answers  


I am new to jsf rich faces. I am using rich faces datatable rich:datatable. On entering the value, values get filtered in table. Now how can i get the value i selected in backing bean?

1 Answers   Hexaware, IBM,


Is java secure? : java security

0 Answers  


What about products that claim to detect malicious applets? : java security

0 Answers  


Differences between intermediate operations and terminal operations of java 8’s stream api?

0 Answers  


cant we call run() method directly instead of calling indirectly through the start() method ? if we do so then what is the problem ?

7 Answers   HSBC, Subex,


what is the serialization?

2 Answers   TCS,


What is contextpath in java?

0 Answers  


How do I run a java project in netbeans?

0 Answers  


what is the function of OS

3 Answers  


How do you type the lambda symbol?

0 Answers  


Categories