JAVA METHODS Flashcards
(14 cards)
are blocks of code that perform specific tasks and
are part of a class. They allow code reusability and modularity by
defining a single block of code that can be executed multiple times
by “calling” the method.
METHODS
THEY ARE USED TO DIVIDE AND FUNCTIONALITIES WITHIN A CLASS SO THAT THE CODE WILL READABLE EVEN IF ITS LONG
METHODS
defines the visibility of the method (public,
private, protected, no modifier(Default)).
Access Modifier
The data type of the value the method returns. Use void if the method does not return a value.
return type
If the method does not return a value, use –
VOID
Name of the Java method. Used to call the method.
METHOD NAME
variable passed to the method for processing.
Parameters
belongs to the class rather than any instance (object). Therefore, it can be
called directly using the class name, without creating an object.
STATIC METHOD
To call an – , you first need to create an object of the class where the
method is defined. Then, use the object to call the method.
instance method
a value that needs to be NOT passed on method so that the method can use that value and perform various operation on it. TRUE OR FALSEW?
FALSE, CAN PASSED
is used to return a value from a method. It is required when a
method produces a result. The type of the returned value must match the method’s
specified return type.
return keyword
- Use a– if the method returns
specific data type
in Java occurs when two or more methods in the
same class have the same name but different parameters.
Method overloading
Overloading allows you to define one behavior for a method while maintaining readability. TRUE OR FALSE?
multiple behaviors