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 / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

If you’re overriding the method equals() of an object, which other method you might also consider?

516


What is the difference between the boolean & operator and the && operator?

525


What does jpa mean?

498


What is java ioc?

489


What is jep in java?

468






What are the types of cookies in java?

497


What is phantom memory?

548


What is spliterator in java se 8?

587


What is lambda expressions action func and predicate?

453


What is entitymanager in jpa?

472


Which interceptor is responsible for setting action javabean properties?

436


What is interceptor in java?

470


What is java persistence api used for?

450


Can java program run without jdk?

512


What is a service layer in java?

413