Why I am not able to execute this program through passing parameters in main class | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why I am not able to execute this program through passing parameters in main class

https://code.sololearn.com/c3fl5220r5Ap/?ref=app

26th May 2020, 4:28 PM
vinay kumar singh
vinay kumar singh - avatar
9 Answers
+ 2
Each set method has to have void instead other declarations looks as follows: public void setEmpId(int empId) { this.empId=empId; } It will be recommended that you make this java tutorial: https://www.sololearn.com/learn/Java/2154/
26th May 2020, 4:49 PM
JaScript
JaScript - avatar
+ 2
vinay kumar singh Ur fix use void in setter becoz they don't return any value
26th May 2020, 4:50 PM
Abhay
Abhay - avatar
+ 1
So what shoul I do? It still says that missing return statement in mutators
26th May 2020, 4:36 PM
vinay kumar singh
vinay kumar singh - avatar
+ 1
Wherever you aren't returning change the function to public void
26th May 2020, 4:45 PM
Abhay
Abhay - avatar
+ 1
// Created by vinay kumar singh public class Employee { int empId; String empName; double salary; public int getEmpId() { return empId; } public void setEmpId(int empId) { this.empId=empId; } public String getEmpName() { return empName; } public void setEmpName(String empName) { this.empName=empName; } public double getSalary() { return salary; } public void setSalary(double salary) { this.salary=salary; } public void display() { System.out.println("\nEmpId:"+getEmpId()); System.out.println("\nSalary:"+getSalary()); System.out.println("\nEmpName:"+getEmpName()); } public static void main(String[] args) { Employee e=new Employee(); e.setEmpId(100); e.setEmpName("Vinay"); e.setSalary(1000.00); e.display(); } }
26th May 2020, 4:49 PM
Abhay
Abhay - avatar
+ 1
Thanks alot guys
26th May 2020, 4:56 PM
vinay kumar singh
vinay kumar singh - avatar
0
In your main...you've mixed up the get...() with your set....().... and change your set....() methods to void.
26th May 2020, 4:33 PM
rodwynnejones
rodwynnejones - avatar
0
Your code with changes:- https://code.sololearn.com/c2eMbUg5ANck/#java (compare)
26th May 2020, 4:43 PM
rodwynnejones
rodwynnejones - avatar