01 - 30 Flashcards

1
Q

Narrowing conversion

  • what is it?
  • how to do?
    o bigger than int
    o equals / smaller than int
A
  • bigger –> smaller
  • bigger than int –> need casting
  • equals / smaller than int –> do not need casting
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

implicit promotion:

  • operand
  • int argument –> accept char?
A
  • operands of mathematical operators are ALWAYS promoted to AT LEAST int and the return value will be AT LEAST int
  • method takes int as argument –> can also takes char
  • -> char will be implicitly promoted to int
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

casting requirements (2)

A
  • IS_A relationship
    (left hand side = super class)
  • compatible data type
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

hierarchy Exception

A

-

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

what must be imported if want to use ArrayList?

A

import java.util.ArrayList;

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

o how to know the number of elements in Array and ArrayList

o length of String & StringBuilder

A

o array –> .length

o ArrayList –> .size()

o String & StringBuilder –> .length()

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

array delaration:

  • new is required?
  • new is not required?
A

o 1 line –> not required

o 2 line –> required

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

operator + when use with String (concatenation) –> vị trí của “ “ ảnh hưởng ntn?

A

-

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

how do derived classes use the variables and methods defined in the superclass?

A

directly as if they were defined in their own classes

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

properties of final:

o class
o method
o variable + how must it be initialized?
o interface
A
  • final class cannot be extended by another class
  • final method cannot be overridden
  • final variables cannot be reassigned a value but can call methods on this variable
    o final variable must be explicitly initialized in the same line of code or initialization block
  • kein final interface
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

when is a variable marked as eligible to be garbage collected? (2)

A
  • can know which are eligible but not sure when
  • when this object can no longer be accessed
    o object’s reference variable is assigned an explicit null value or is reinitialized
    o this object goes out of scope
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

4 loại access modifiers + range of accessability

A

public > protected > default > private

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

can static method access non-static variable?

A

no

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

can use this and super in a static method?

A

no

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

super.method # BaseClassName.method?

A

BaseClassName.method only applies to static method

super –> no limit

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

can switch work with Array?

A

no

17
Q

what type of methods cannot be overridden? (2)

A

static, final

18
Q

define variables with the same name

A

local variables - instance variables

local variables - class / static variables

19
Q
  • operator precedence: highest and second heighest
  • && và ||
  • == và =
A
  • postfix - unary
  • && > ||
  • == > =
20
Q

overriding - overridden methods:
- return type of
o primitive
o object

  • restrictivity of access modifiers
  • what kind of method cannot be overridden?
  • overriding: static and non-static method
A
  • primitive = same
  • object = same or subclass of overridden
  • access modifiers of the overriding –> same or less
  • cannot override final and static method
  • cannot override/hide a static method with a non-static method and vice versa
21
Q

initial size:

  • ArrayList
  • StringBuilder
A

ArrayList –> 10

StringBuilder –> 16

22
Q

o method parameter is variable arguments –> what must it be? (2)
o meaning of variable arguments
o how to write?

A

o only 1 + last in parameter list

o (int… days)

23
Q

WrapperClass:

o mutable? How to compare?
o provide what mechanism? (2)
o constructor accept what? (2)
o can 2 primitive wrapper be compatible?
o PrimitiveWrapper.MIN_VALUE + 1 =?
A
  • immutable
  • == operator –> compare with compatible primitive
  • 2 primitive wrappers are never compatible
  • primitive wrapper constructor accepts
    + compatible primitive value
    + the String representation
  • PrimitiveWrapper.MIN_VALUE + 1 == PrimitiveWrapper.MAX_VALUE
24
Q

startsWith, endsWith

  • what is?
  • accepted type?
A
  • determines whether a String starts / ends with a specified prefix, specified as a String
  • only String with “ “
25
Q

when instance variables and methods bind?

A

instance variables bind at compile time

methods bind at runtime

26
Q

package:

o if present, how many time can a package statement appear?
o can a class from default package be used in named packaged class?
o how is default package imported in classes and interfaces defined in the same directory?
A
  • if present, the package statement must appear exactly once in a class
  • a class from a default package can’t be used in any named packaged class, regardless of whether they are defined within the same directory or not
  • can define multiple classes and interfaces in the same Java source code file
  • classes and interfaces defined in the same Java source code file cannot be defined in separate packages
27
Q

import static or static import?

A

import static