+ 2
Will anyone see my error??
7 Respostas
+ 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.
+ 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.
+ 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 : "" );
}
0
Thanks
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();
}
}
0
Bhai tum kaha se hoo
0
Andhra Pradesh se hi bhai