public class Friend {
String name;
int age;
char sex;
public void initialize(String name){
this.name = name;
}
public void initialize(String name , int age){
this.name = name;
this.age = age;
}
public void initialize(String name , int age, char sex){
this.name = name;
this.age = age;
this.sex = sex;
}
public static void main(String[] args) {
Friend obj1 = new Friend();
System.out.println(obj1.initialize("a"));
Friend obj2 = new Friend();
System.out.println(obj2.initialize("a",18));
Friend obj3 = new Friend();
System.out.println(obj3.initialize("a",19,'M'));
}
}
help please...what is wrong in this code?
Under discussion
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Baljinder Singh
22 September 2018, 19:35
In the main method, you are calling a void returning method and printing it, which is not right,
It will keep giving you,
For example, for first object,
instead that you should be doing,
Same goes for second and third object. +2
Shahanshah Alam
22 September 2018, 19:40
got it...
thanks bro...
0