[Solved] Help me out am getting error | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

[Solved] Help me out am getting error

Why is it showing out error help me out class Islamiya{ String name1; String name2; String name3; String name4; } Islamiya(int n1, int n2, int n3, int n4){ this.name1=n1; this.name2=n2; this.name3=n3; this.name4=n4; } void display(){ System.out.println(n1 + n2 + n3 + n4); } public class Main{ public static void main(String args []){ Islamiya n1= new Islamiya("Yadoko"); Islamiya n2= new Islamiya ("malam Hassan"); Islamiya n3= new Islamiya ("malam shehi"); Islamiya n4= new Islamiya ("baban malam"); n1.display(); n2.display(); n3.display(); n4.display(); } }

21st Jul 2019, 10:51 AM
Dprincebh
Dprincebh - avatar
13 Answers
+ 2
class Islamiya{ String name1; Islamiya(String n1){ this.name1=n1; } void display(){ System.out.println(name1); } } public class Main{ public static void main(String args []){ Islamiya n1= new Islamiya ("Yadoko"); Islamiya n2= new Islamiya ("malam Hassan"); Islamiya n3= new Islamiya ("malam shehi"); Islamiya n4= new Islamiya ("baban malam"); n1.display(); n2.display(); n3.display(); n4.display(); } }
21st Jul 2019, 1:01 PM
zemiak
+ 2
You are passing string value into int variable in your constructor. That is your error. Also in your display method you are using n1, n2, n3, n4 which is not a variable in your class. These variable are just used in constructor.
21st Jul 2019, 10:54 AM
Chetali Shah
Chetali Shah - avatar
+ 1
Still showing error class, interface or enum expected at the line of the constructor Islamiya (String n1, String n2, String n3, String n4)
21st Jul 2019, 11:26 AM
Dprincebh
Dprincebh - avatar
+ 1
Okay thanks
21st Jul 2019, 11:57 AM
Dprincebh
Dprincebh - avatar
0
try this void display() { System.out.println(this.name1+this.name2+this.name3+this.name4)
21st Jul 2019, 11:17 AM
Dwi Novianto Nugroho
Dwi Novianto Nugroho - avatar
0
Because you already close "}" the class then your constructor not executed yet
21st Jul 2019, 11:27 AM
Dwi Novianto Nugroho
Dwi Novianto Nugroho - avatar
0
This is the new editied code https://code.sololearn.com/cD2yf8B34S9L/?ref=app It's showing "an error occured". It is not executing
21st Jul 2019, 11:31 AM
Dprincebh
Dprincebh - avatar
0
Islamiya n1= new Islamiya("Yadoko"); ^^ You have 4 constructor in Islamiya. But you just add only 1 value
21st Jul 2019, 11:33 AM
Dwi Novianto Nugroho
Dwi Novianto Nugroho - avatar
0
Bro. Am already confused
21st Jul 2019, 11:45 AM
Dprincebh
Dprincebh - avatar
0
In details pls
21st Jul 2019, 11:45 AM
Dprincebh
Dprincebh - avatar
0
Islamiya(String n1, String n2, String , String n4) But you enter only one value Islamiya n1 = new Islamiya("Yadoko");
21st Jul 2019, 11:57 AM
Dwi Novianto Nugroho
Dwi Novianto Nugroho - avatar
0
Can you see my code. It already fixed. Just edit what do you need
21st Jul 2019, 11:57 AM
Dwi Novianto Nugroho
Dwi Novianto Nugroho - avatar
0
Thanks bro
21st Jul 2019, 4:53 PM
Dprincebh
Dprincebh - avatar