Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

Program after correction is class HowToReturnObject int a HowToReturnObjectint iai include ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Successful Project Management

Authors: Jack Gido, Jim Clements

4th Edition

9780324656152, 324656130, 978-0324656138

More Books

Students also viewed these Programming questions

Question

Describe Hartleys seven varieties of pleasure.

Answered: 1 week ago