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(); } }
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();
}
}
+ 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.
+ 1
Still showing error class, interface or enum expected at the line of the constructor Islamiya (String n1, String n2, String n3, String n4)
+ 1
Okay thanks
0
try this
void display() {
System.out.println(this.name1+this.name2+this.name3+this.name4)
0
Because you already close "}" the class then your constructor not executed yet
0
This is the new editied code
https://code.sololearn.com/cD2yf8B34S9L/?ref=app
It's showing "an error occured". It is not executing
0
Islamiya n1= new Islamiya("Yadoko");
^^
You have 4 constructor in Islamiya. But you just add only 1 value
0
Bro. Am already confused
0
In details pls
0
Islamiya(String n1, String n2, String , String n4)
But you enter only one value
Islamiya n1 = new Islamiya("Yadoko");
0
Can you see my code. It already fixed. Just edit what do you need
0
Thanks bro