Sorry if my questions are a little dumb. I'm young and I'm still learning.
I have been asking around and I dont understand the printData method? What does it really do? How is it different from System.out.println? Also what is 'return;' for? As in why do I need it?
Sorry if there are too many questions.
All help is greatly appreciated <3
That code shows the printData method is in the Student class. Your question is: why did the author write that method instead of just using the print method. It looks like the method prints out the contents of 3 variables in the Student class object.
Since some of the variables are private the code to print them needs to be in the Student class. Often writers of a class will add a toString method to a class that will return the Strings that are printed in the three print statements that code outside of the class can use to display the Student class's variables.
Writing a printData() method like that isn't really in the Java® idiom. The Java® idiom is to override Object#toString(). Because the Object class implements such a method, every object ever seen has an implementation of it. Unfortunately the Object version is too basic for most use, so you have to override the method:-Alternative version, but you might not be familiar with the % tags:-Now you can write the following anywhere:-Note the warning about subsequent changes: you don't want users thinking that format is fixed for ever. If you return those three data from toString(), be sure to provide getXXX() methods for all three, too.
I prefer not to end what I return from toString() with a line end.
Your line 25 is incorrect. Use a getXXX() method instead, and give all fields private access. Don't write a no‑arguments constructor. If you have three data, use a three‑argument constructor.