0

how can I print the everthing the object"Abdullah" has got .

class person{ String lname; String fname; String SSN; } class A extends person { String Studentid ; String classname[] =new String [3]; public static void main(String[] args) { A abdullah = new A(); abdullah.lname="Muhammadi"; abdullah.fname="abdullah"; abdullah.SSN="1225462655"; abdullah.classname[0]="Math"; abdullah.classname[1]="Biology"; abdullah.Studentid="11111111"; System.out.println(abdullah()); // here I want to print whole object Abdullah how do I code it ????? ? } }

27th Apr 2019, 9:47 PM
Humayoon Rafei
Humayoon Rafei - avatar
7 ответов
+ 2
I added two versions: override toString() or write an own print method https://code.sololearn.com/cOJ386DwzqI7/?ref=app
27th Apr 2019, 10:37 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
Can you give an example of an expected output?
27th Apr 2019, 10:19 PM
Denise Roßberg
Denise Roßberg - avatar
27th Apr 2019, 10:42 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
Humayoon Rafei No. Only printing the object (without overriding toString()) would give you something like this: A[@24224] -> the class name and inside the brackets a hashcode.
27th Apr 2019, 11:06 PM
Denise Roßberg
Denise Roßberg - avatar
0
here it is but i dont want to call each line i just want to call one thing and it would print all of it as below can a constructor do that ??? Muhammadi abdullah 122546255 Math Biology 11111111
27th Apr 2019, 10:24 PM
Humayoon Rafei
Humayoon Rafei - avatar
0
so there isnt any single command line to print all contents encapsulated in an object not taking help of tostring or making print function????
27th Apr 2019, 10:45 PM
Humayoon Rafei
Humayoon Rafei - avatar
0
thanks for the answers
27th Apr 2019, 10:45 PM
Humayoon Rafei
Humayoon Rafei - avatar