Intro to Classes, Objects, Methods and Strings Flashcards

1
Q

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

a) static

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
b) Keyword \_\_\_ in a class declaration is 
followed immediately by the class’s name.
A

b) class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

c) Keyword ___ requests memory from the system to store an object, then calls the
corresponding class’s constructor to initialize the object.

A

c) new

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

d) Each parameter must specify both a(n) ___ and a(n) ___ .

A

d) type, name

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

e) By default, classes that are compiled in the same directory are considered to be in the
same package, known as the ___ .

A

e) default package

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

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) ___ .

A

f) instance variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

g) Java provides two primitive types for storing floating-point numbers in memory: ___ and ___ .

A

g) float, double

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

h) Variables of type double represent ___ floating-point numbers.

A

h) double-precision

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

i) Scanner method ___ returns a double value.

A

i) nextDouble

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

j) Keyword public is an access ___ .

A

j) modifier

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

k) Return type ___ indicates that a method will not return a value.

A

k) void

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

l) Scanner method ___ reads characters until it encounters a newline character, then returns those characters as a String.

A

l) nextLine

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

m) Class String is in package ___ .

A

m) java.lang

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

n) A(n) ___ is not required if you always refer to a class with its fully qualified class name.

A

n) import declaration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

o) A(n) ___ is a number with a decimal point , such as 7.33, 0.0975 or 1000.12345.

A

o) floating-point number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

p) Variables of type float represent ___ floating-point numbers.

A

p) single-precision

17
Q

q) The format specifier ___ is used to output values of type float or double.

A

q) %f

18
Q

r) Types in Java are divided into two categories— ___ types and ___ types.

A

r) primitive, reference

19
Q

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

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

20
Q

b) An import declaration is not required when one class in a package uses another in the same package.

A

b) True

21
Q

c) Empty parentheses following a method name in a method declaration indicate that the method does not require any parameters to perform its task.

A

c) True

22
Q

d) Variables or methods declared with access modifier private are accessible only to methods of the class in which they’re declared.

A

d) True

23
Q

e) A primitive-type variable can be used to invoke a method.

A

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.

24
Q
f) The compiler provides a default constructor with no parameters in any class that does
not explicitly include a constructor.
A

f) True

25
Q

g) Every method’s body is delimited by left and right braces ({ and }).

A

g) True

26
Q

h) Primitive-type local variables are initialized by default.

A

h) False. Primitive-type instance variables are initialized by default. Each local variable must explicitly be assigned a value

27
Q

i) Reference-type instance variables are initialized by default to the value null.

A

i) True

28
Q

j) Any class that contains public static void main( String[] args ) can be used to execute an application.

A

j) True

29
Q

k) The argument types in the method call need not be consistent with the types of corresponding parameters in the method’s declaration.

A

k) False. The argument types in the method call must be consistent with the types of corresponding parameters in the method’s declaration

30
Q

l) Floating-point values that appear in source code are known as floating-point literals and are type float by default.

A

l) False. Such literals are of type double by default

31
Q

Explain the public and private access modifiers in brief.

A

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.

32
Q

Explain the purpose of a method parameter. What is the difference between a parameter and an argument?

A

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.