03 Prelim CP2 Flashcards

1
Q
  • It is a special method that is used to CREATE and INITIALIZE an object.
  • Using the “new” keyword calls a ______.
  • It must have the same name with the class to which it belongs to.
  • It does not have a return type.
A

CONSTRUCTOR

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  • These are shared by all the objects of its class.
  • ______ _____ that are not constants should be private.
  • These should be accessed or changed only via accessor and mutator methods

Sample:
private static double numOfAccounts;

A

STATIC VARIABLES

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  • can be invoked without using any object

-invoked by using the class name instead of the object name

Sample:
public static int getNumofAccounts() {
return numOfAccounts;
}

A

STATIC METHODS

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

How to invoke a static method:

A

variableName = ClassName.staticMethod(arg);

Example:
inches = UnitConverter.convertFeetToInches(2.6);
feet = UnitConverter.convertInchesToFeet(53.7);

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

When you declare a variable or a method as _____, it belongs to the class rather than to a specific instance.

This means that only one instance of a static member exists, even if you create multiple objects of the class or if you do not create any. It will be shared by all objects.

A

STATIC

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  • Provides a number of standard mathematical
    methods.
  • Does not require an import statement.
  • All the methods in this class are static.
  • it returns the absolute value of its parameter.

-You do not need to create an object of the Math class to use it. To access it, just type in Math. and the corresponding method.

Sample:
int higherNum = Math.max(7, 9);

A

MATH CLASS

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

What method in Math class returns the absolute value of its parameter

A

Math.abs()

Sample:
int a = Math.abs(-10);

// output “10”

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

What method in Math class returns the smallest parameter.

A

Math.min()

Sample:
int m = Math.min(10, 20);

// output “10”

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

What method in Math class takes two (2) parameters and returns the first parameter raised to the power of the second parameter.

A

Math.pow()

Sample:
double p = Math.pow(2, 3);

// output “8.0” (2^3 = 8)

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

What method in Math class returns a random number in the range >0 and <1

A

Math.random();

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

What method in Math class returns the largest parameter.

A

Math.max()

Sample:
int m = Math.max(10, 20);

// output “20”

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

What method in Math class returns the round number of the given parameter:

A

Math.round();

Sample:
Math.round(6.2); // 6
Math.round(6.8); // 7

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

What method in Math class returns the highest closest number of the given parameter:

A

Math.ceil();

Sample:
Math.ceil(3.2); // 4.0
Math.ceil(3.8); // 4.0

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

What method in Math class returns the lowest closest number of the given parameter:

A

Math.floor();

Sample:
Math.floor(3.2); // 3.0
Math.floor(3.8); // 3.0

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

What method in Math class returns the square root of the given parameter:

A

Math.sqrt();

Sample:
Math.sqrt(4.0); // 2.0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
  • _______the method name is when you give two (2) or more methods the same name within the same class.
  • Methods
    with the same name must have a different number of
    parameters or have corresponding parameters with differing
    types.
A

OVERLOADING

17
Q

METHODS with the SAME NAME must have a DIFFERENT number of
PARAMETERS or have corresponding parameters with DIFFERING
types.

-True
-False