Harder Java Cards Flashcards Preview

OCA Java 8 Exam > Harder Java Cards > Flashcards

Flashcards in Harder Java Cards Deck (22)
Loading flashcards...
1

What are the primitive data types?

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

2

Can a user define their own primitive data types?

No they cannot.

3

What is the printed when you use a variable of type char without initializing it (assuming that the declaration is an instance variable).

The default value of char is 0, which when printed, translates to an empty space.

4

When assigning a unicode value to a char variable, what is the allowed range?

'\u000' to '\uffff'

5

Can an identifier have the same spelling as a Java keyword?

Yes, but only if the case is changed, because Java is case sensitive. Int is a valid identifier, while int is not (because int is a reserved word).

6

Can a double variable be assigned to an int variable?

Yes, but only if the variable is cast to an int.

7

Can an int variable be assigned to a double variable?

Yes, and no casting is needed because Java widens the variable.

8

In what ways can an object of a wrapper class (i.e. Integer) be created?

By assigning a primitive to a wrapper class variable (autoboxing), by using the constructors of the wrapper class, and by calling the static method valueOf( ).

9

What wrapper classes define a constructor that accepts a String argument representing the value that needs to be wrapped?

All of them except for Character.

10

Which wrapper classes define a no argument constructor?

None of them.

11

What is autoboxing?

When a primitive value or variable is assigned to an reference variable of its wrapper type, Java automatically creates an object of that type and assigns its value to the primitive value passed.

12

What is unboxing?

When an object of a primitive wrapper class is converted to its corresponding primitive value.

13

How can you compare objects of wrapper classes for equality?

You can use the == operator because Java unboxes the wrapper objects into their corresponding primitives, and also use .equals( ) because it is overridden in all of the wrapper classes to compare the values of the objects passed.

14

What will happen if a wrapper reference variable that refers to null is unboxed?

Java will throw a RuntimeException of NullPointerException.

15

What happens to a char primitive when it is used as an operand to arithmetic operators?

Its corresponding ASCII value is used.

16

What is binding in the context of inheritance?

Binding refers to the resolving of variables or methods that would be called for a reference variable.

17

When are instance variables bound?

At compile time.

18

When are methods bound?

At run time.

19

What is variable hiding?

Variable hiding happens when a variable is declared in a local scope that has the same name as one that exists in the outer scope.

20

What happens when a child class defines a static method with the same signature as a static method in the parent class?

The child class method hides the parent class method.

21

When talking about polymorphism, what is the difference between method hiding and method overriding?

Hiding methods only happens when the methods are static, and binding occurs at compile time, as static methods are not polymorphic. Overriding instance methods are bound at runtime.

22

How is the Gregorian calendar system defined in the core classes in the Date-Time API?

ISO-8601 is defined as