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
Step: 1
Program after correction is class HowToReturnObject int a HowToReturnObjectint iai include ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get StartedRecommended Textbook for
Successful Project Management
Authors: Jack Gido, Jim Clements
4th Edition
9780324656152, 324656130, 978-0324656138
Students also viewed these Programming questions
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
View Answer in SolutionInn App