- Objects
- Classes
- Inheritance
-
Programming in Java on Your Computer - Classes and Objects in BlueJ
- Trying out Code in BlueJ
- The Code for Creating and Using Objects
- Source Code and Methods
- Accessors and Mutators
- Constructor Code
- Scope
- Inheritance
-
BlueJ Review - Class Code
- Simple Debugging
- Interactive Picture
- Refactoring Code with Inheritance
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:
Access
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.
Comments
Honzis
Dec 23, 6:44 AMreturn ("ID: " +SID);
after submission results in incorrect?
Victoria Holland
Jan 17, 5:14 AMHonzis, you don't need to include the brackets around the answer.
xiaochayou
Apr 22, 3:35 AMAs a college student who major in EE, I love this kind of learning java !