Functions and Modules Flashcards
What is a method in Java?
a method is a section of the program that contains a set of instructions. When the method is called, the set of instructions within the method is executed.
What are parameters in a Java method?
data that are inputted or passed into the method
Identify the name, parameters in the Java method below:
public int calculateAge ( int m, int n) {
statements…}
calculateAge is the name of the method
m,n are the parameters
What is the first method executed in Java?
the main method
Why is the main method in Java declared as static?
because it allows the main method to be called as the first method without having to create an instance of the method.
How is the return value declared in a method?
By the data type alone before the method name
Can Java methods return more than one value?
No Java methods can only return one or no values.
The number of strings passed into the main method’s local variable named args can be obtained via _____.
args.length
The number of elements stored in any Java array is kept in an internal property named length. Therefore args.length will return the number of elements in the String array args.
_____ are passed to the main method as an array of String objects.
The command line options.
The space separated command line options (which occur AFTER the name of the file containing the Java program) are passed to the main method.
If you want to protect members of a class, but still allow other classes in the package, or subclasses to use them, the __________ keyword can be used.
protected
A ____________ is a class that inherits variables and methods from another class. Private members can’t be shared down to children, but protected members can.
subclass
A __________ in Java is like a project: it is a group of similar class types all contained within the same set of code.
package
The _________ keyword provides the highest level of protection for members of classes.
private
It is recommended to create most methods and variables as _____.
private
Which type of variable or method is protected but can be used with classes in the package (and also subclasses)?
Protected
The Java _______ keyword protects code, variables, classes, and methods. It ensures you can’t create subclasses from the main class. It ensures variables stay local to their methods.
final