Unit 3: Methods/Functions Flashcards
Define: Method
A collection of statements that are grouped together to perform an operation (e.g. main())
True or False: In Java, a method is always defined inside a class
True
Define: Pre-defined method
Methods already written and defined inside classes and provided by Java. Organized and stored in the standard packages (e.g. java.lang.Math)
Define: Programmer-defined method
Programmer writes the method definition inside a class based on their requirement, if no pre-defined method is available. The method definition includes modifier(s), return type, method name, and types and number of parameters
Why are methods useful?
A complex program can be broken down into sub tasks, each of which is easy to manage and implement (this is known as a modular programming approach)
True or False: Generally, the driver class in Java contains static methods
True
True or False: A method with a static modifier is not a static method
False
True or False: A static method can only call a non-static method after creating an object of that class it belongs to
True
True or False: In Java, a method can be defined inside another method and does not have to be defined as a separate entity
False
Define: Void method
A method that does not return any value
Define: Value-returning method
A method that returns a value using a return statement
If a static method is called from a different class, it is done by using the ___________ followed by ___________
Name of the class, the dot (.) operator
Define: Method signature
The combination of the method name (a valid identifier which can not be a keyword) and the data/object-types in the parameter list that contains formal parameters
Define: Formal parameters
The variables declared in the method header
Define: Actual parameters
Parameters involved in the method call line, there is no need to specify the datatype or method type in these parameters
Define: Return-value type
The datatype of the value the method returns via a return-statement after it is done with the calculation
True or False: A method can not return more than one object
True
If a method does not return a value, the keyword ______ is used in place of return-value type
void
When a method is called, the arguments must agree with the formal parameters in ____, _____________, and _______
Order, number of parameters, data types
True or False: The variable names in the method header and in the arguments of the method-call can be different
True
Define: Pass by value
When using a variable inside a method, any change to the value of the variable inside the called method does not change the original value in the calling method
Define: Pass by reference value
When passing a reference-value of an object to a called method, the original value in the calling method can be changed from the called method
Define: Stack (in RAM)
Stores local primitive variables (variables inside a program block), formal parameters, and local reference variables. Managed by the compiler in LIFO (Last in First out) basis
Define: Heap (in RAM)
Stores dynamic/runtime variables; in Java, whenever we create any object, it is created in the heap space