Question: Find the errors of the following Java program. Also, correct the following Java code. You cannot reduce the mode of access specifiers. You may add

Find the errors of the following Java program. Also, correct the following Java code. You cannot reduce the mode of access specifiers. You may add new methods/variables.




classHowToReturn Object{
int a;
HowToReturnObject(int i){a=i;
HowToReturnObjectincrByValue(int i) {
HowToReturnObject temp = new HowToReturnObject(a+i);
returntemp;
}
}
Public class Return Obj {
public staticvoid main(String args[]) {
HowToReturnObject obj1 = new HowToReturnObject(5);
HowToReturnObject obj2 = obj1.incrByValue(3);
System.out.println(obj2.a);
obj2 = obj2incrByValue(15);
System.out.println(obj2.a)
}

Step by Step Solution

3.44 Rating (163 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Program after correction is class HowToReturnObject int a HowToReturnObjectint iai include ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!