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