Source Code and Methods

Premium Content - Free Preview

The previous nodes didn't involve changing actual code, you just created Objects from Classes and interacted with their methods. The actual Classes are created by editing their source code, which can be done in BlueJ by double-clicking on any class icon.


This will open up the source code file:


Now you can see some of the code you interacted with before. You don't need to worry about every detail of code, but find the method getStudentID. We already covered how methods take in parameters, but now let's examine the beginning of a method header:


public String getStudentID()

public means the method is available to any other Class or Object in the world. private means the method is only for internal object use, but cannot be called by other Objects. When you click on an object on BlueJ's Object bench, you can see the public methods but not the private ones since no one outside the Object has access to them.

Return Type
String means the method returns an item of type String. In Java, every method needs to declare its return type. It can either be an Object, a data type like int or boolean, or it can be void which means it returns nothing.

End of Free Content Preview. Please Sign in or Sign up to buy premium content.


All Node Comments
Contact Us
Sign in or email us at [email protected]