Intro to Classes, Objects, Methods and Strings Flashcards
a) A ___ method is a special method that you can call without first creating an object of the class in which it is declared.
a) static
b) Keyword \_\_\_ in a class declaration is followed immediately by the class’s name.
b) class
c) Keyword ___ requests memory from the system to store an object, then calls the
corresponding class’s constructor to initialize the object.
c) new
d) Each parameter must specify both a(n) ___ and a(n) ___ .
d) type, name
e) By default, classes that are compiled in the same directory are considered to be in the
same package, known as the ___ .
e) default package
f) When each object of a class maintains its own copy of an attribute, the field that represents the attribute is also known as a(n) ___ .
f) instance variable
g) Java provides two primitive types for storing floating-point numbers in memory: ___ and ___ .
g) float, double
h) Variables of type double represent ___ floating-point numbers.
h) double-precision
i) Scanner method ___ returns a double value.
i) nextDouble
j) Keyword public is an access ___ .
j) modifier
k) Return type ___ indicates that a method will not return a value.
k) void
l) Scanner method ___ reads characters until it encounters a newline character, then returns those characters as a String.
l) nextLine
m) Class String is in package ___ .
m) java.lang
n) A(n) ___ is not required if you always refer to a class with its fully qualified class name.
n) import declaration
o) A(n) ___ is a number with a decimal point , such as 7.33, 0.0975 or 1000.12345.
o) floating-point number
p) Variables of type float represent ___ floating-point numbers.
p) single-precision
q) The format specifier ___ is used to output values of type float or double.
q) %f
r) Types in Java are divided into two categories— ___ types and ___ types.
r) primitive, reference
a) By convention, method names begin with an uppercase first letter, and all subsequent
words in the name begin with a capital first letter.
a) False. By convention, method names begin with a lowercase first letter and all subsequent words in the name begin with a capital first letter
b) An import declaration is not required when one class in a package uses another in the same package.
b) True
c) Empty parentheses following a method name in a method declaration indicate that the method does not require any parameters to perform its task.
c) True
d) Variables or methods declared with access modifier private are accessible only to methods of the class in which they’re declared.
d) True
e) A primitive-type variable can be used to invoke a method.
e) False. A primitive-type variable cannot be used to invoke a method—a reference to an object is required to invoke the object’s methods.
f) The compiler provides a default constructor with no parameters in any class that does not explicitly include a constructor.
f) True
g) Every method’s body is delimited by left and right braces ({ and }).
g) True
h) Primitive-type local variables are initialized by default.
h) False. Primitive-type instance variables are initialized by default. Each local variable must explicitly be assigned a value
i) Reference-type instance variables are initialized by default to the value null.
i) True
j) Any class that contains public static void main( String[] args ) can be used to execute an application.
j) True
k) The argument types in the method call need not be consistent with the types of corresponding parameters in the method’s declaration.
k) False. The argument types in the method call must be consistent with the types of corresponding parameters in the method’s declaration
l) Floating-point values that appear in source code are known as floating-point literals and are type float by default.
l) False. Such literals are of type double by default
Explain the public and private access modifiers in brief.
As the names suggest, variables or methods declared with access modifier private are accessible only to methods of the class in which they’re declared, whereas the variables or methods declared with access modifier public are “accessible to the public”—they can be accessed from methods of other classes.
Explain the purpose of a method parameter. What is the difference between a parameter and an argument?
A parameter represents additional information that a method requires to perform its task. Each parameter required by a method is specified in the method’s declaration. An argument is the actual value for a method parameter. When a method is called, the argument values are passed to the corresponding parameters of the method so that it can perform its task.