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 ????? ? } }
7 Antworten
+ 2
I added two versions:
override toString()
or write an own print method
https://code.sololearn.com/cOJ386DwzqI7/?ref=app
+ 2
Can you give an example of an expected output?
+ 2
Here you find more about the toString() method: https://www.google.de/amp/s/www.geeksforgeeks.org/overriding-tostring-method-in-java/amp/
+ 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.
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
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????
0
thanks for the answers