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 / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What is meant by annotations in java?

487


Which method is used to create the daemon thread?

549


What is an actionevent in java?

454


What is ibatis in java?

516


What is the java api?

498






What if the main method is declared as private?

472


What is factory pattern in java?

440


can a program use more than one command-line argument?

489


What is exe file in java?

502


Is openjdk the same as jdk?

502


What is the use of rs next () in java?

493


What is a java executable jar file?

475


What is data encapsulation?

527


Describe the principles of oops.

498


Which is better openjdk or oracle jdk?

457