CSCI 1006 Lecture Notes - Lecture 2: Return Type
● Level of protection →
● protects certain values of an object.
● It cannot be accessed from objects of a different type.
● But it can be accessed from objects of the same class.
■ So you can simple refer from one instance of an object to the variable of
another instance of the object within one class. For example,
“otherBankAccount.balance”.
● Instance variables are usually private, while methods are usually public.
● Return type → states which type, if any, of primitive type or class will be returned.
● All methods must have a return type, but not necessarily a value.
● “Void” can be a return type.
■ Usually, methods that change something, or arrange something, will have
a void return type.
■ In void methods, simply writing “return” signifies the end of the method.
● Returned values are stored, but not displayed on screen unless specifically
programmed.
■ Returned values are used for further computing.
■ Display must be mentioned in a different part of the code.
● The word “return” is used to return a value.
■ “Return” → method is done, and will not continue.
● Name of the method:
● No spaces.
● No Java keywords.
find more resources at oneclass.com
find more resources at oneclass.com
Document Summary
It cannot be accessed from objects of a different type. But it can be accessed from objects of the same class. So you can simple refer from one instance of an object to the variable of another instance of the object within one class. Instance variables are usually private, while methods are usually public. Return type states which type, if any, of primitive type or class will be returned. All methods must have a return type, but not necessarily a value. Usually, methods that change something, or arrange something, will have a void return type. In void methods, simply writing return signifies the end of the method. Returned values are stored, but not displayed on screen unless specifically programmed. Returned values are used for further computing. Display must be mentioned in a different part of the code. The word return is used to return a value. Return method is done, and will not continue.