13th Apr 2021, 3:44 PM
Kajal Kumari
7 Answers
+ 4
public void showdata() { //System.out.println(id+""+name); System.out.println(id + " " + name + " " + age); } Missing a + operator between <name> and " ". First print statement is redundant, so I guess it can be commented or removed.
13th Apr 2021, 3:57 PM
Ipang
+ 3
Also if you want to have a different showdata() for when age is not part of the object you will need to create a showdata() to be used in that case.
13th Apr 2021, 4:29 PM
Paul K Sadler
Paul K Sadler - avatar
+ 1
// if 0 is not valid age public void showdata() { System.out.printf( "id:%d, name:%s%s\n", id, name, age > 0 ? ", age:" +age : "" ); }
14th Apr 2021, 2:00 AM
zemiak
0
Thanks
14th Apr 2021, 2:41 AM
Kajal Kumari
0
public class Congo { int id; String name; int age; Congo(int i,String n) { id=i; name=n; } Congo(int i,String n,int x) { id=i; name=n; age=x; } public void showdata() { System.out.println("id+"+"name"); System.out.println("id"+"name"+"age"); } } class Hello { public static void main(String[] args) { Congo obj=new Congo(5,"karan"); Congo obj1=new Congo(6,"kajal",67); obj.showdata(); obj1.showdata(); } }
14th Apr 2021, 4:29 PM
Puri Jagannadh Muralasetti
Puri Jagannadh Muralasetti - avatar
0
Bhai tum kaha se hoo
15th Apr 2021, 3:30 PM
Hariom gupta
Hariom gupta - avatar
0
Andhra Pradesh se hi bhai
17th Apr 2021, 3:56 PM
Puri Jagannadh Muralasetti
Puri Jagannadh Muralasetti - avatar