CHP5 - Methods Flashcards

1
Q

method declaration rule

A

-First comes access modifier.

Access modifiers and optional specifiers can be listed in any order, but once the return type is specified, the rest of the parts of the method are written in a specific order: name, parameter list, exception list, body.

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

protected access modifier

A

Members with the protected modifier are accessible:
- Within the same package (like default access).
- In subclasses, even if they are in a different package.

Useful when designing classes for inheritance.

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

Default (Package-Private) Access Modifier

A

-If no access modifier is specified, the member is package-private.
-Members are accessible only within the same package.

-Cannot be accessed from subclasses if they are in a different package.

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

Variable naming rules

A

An identifier may only contain letters, numbers, currency symbols, or _ .

Also, first character is not allowed to be a number, and reserved words are not allowed.

Single underscore character is not allowed.

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

Method signature

A

It is composed of the method name and parameter list.

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

Local variable modifier

A

There is only one modifier that can be applied to local variable.

It is final modifier.

We can use var and final together.

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

Does using final modifier mean we cant modify the data?

A

Nope.

The final attribute refers only to the variable reference;

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

final description

A

Specifies that the instance variable must be initialized with each instance of the class exactly once

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

volatile description

A

Instructs the JVM that the value in this variable may be modified by other threads

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

transient

A

Used to indicate that an instance variable should not be serialized with the class

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

null as varargs

A

Triggers NullPointerException. Becuase it tries to determine the length of null

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

static method call

A

You can use instance of the object to call a static method.
The compiler checks for the type of the reference and uses that instead of the object.

static methods can be called with even null objects.

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

Autoboxing

A

Process of converting a primitive into its equivalent wrapper class

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

Unboxing

A

Process of converting a wrapper class into its equivalent primitive

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

Implicit Casting (Widening)

A

– Automatic and safe conversion (small → large type).

byte → short, int, long, float, double
short → int, long, float, double
char → int, long, float, double
int → long, float, double
long → float, double
float → double

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

Explicit Casting (Narrowing)

A

– Manual conversion (large → small type) with potential data loss.

double → float, long, int, short, byte
float → long, int, short, byte
long → int, short, byte
int → short, byte, char
short → byte

16
Q

Is {true, true} proper array declaration?

A

NO.

new boolean[] {true, true} is proper declaration

17
Q

Are Rope.swing() and new Rope().swing() same?

A

Yes if swing() method is public static method

18
Q

static final initialization period

A

If a variable is static final, it must be set exactly once, and it must be in the declaration line or in a static initialization block.

19
Q

static variable access from initializers

A

Both static and instance initializers are able to acess static variables.

20
Q

clone() method

A

a clone() creates shallow copy which means elements of original and duplicate point to the same objects