CSCI 1006 Lecture Notes - Lecture 2: Return Type

14 views3 pages
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
Unlock document

This preview shows page 1 of the document.
Unlock all 3 pages and 3 million more documents.

Already have an account? Log in

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions