Data Types Flashcards

1
Q

What are the two constructors of the Boolean wrapper class?

A

Boolean (boolean) and Boolean (String)

This second constructor is deprecated but still shows up on the exam.

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

What are the two static helper methods for the Boolean wrapper class?

A

parseBoolean and valueOf

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

What does the Boolean.parseBoolean(String) method do?

A

It returns a primitive type that is equal to the value true if, and only if, the string argument is not null and returns “true” (as a constant Boolean.TRUE), regardless of case.

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

What type do the parseWrappername( ) methods (e.g. parseInteger ( ) or parseBoolean( ) ) return?

A

Primitive types, not objects.

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

What do Boolean.valueOf(String) and its overloaded method Boolean.valueOf(boolean) return?

A

A reference to either Boolean.TRUE or Boolean.FALSE (constants of the wrapper class Boolean).

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

What does the following evaluate to?

new Boolean(“true”) == Boolean.TRUE

A

It evaluates to false.

Both have a Boolean wrapper object containing the value true, but they are different objects.

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

Do any wrapper classes have a no-args constructor?

A

No.

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

What parameters does Long.valueOf( ) takes?

A

None.

This means that Long.valueOf(“123”) does not compile.

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

Can variables be assigned as abstract?

A

No.

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

If a class is not nested, what modifiers can it have that are legal?

A

final, abstract, and public.

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

If a class is nested, what modifiers can it have?

A

Public, private, protected, abstract, and final.

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

How can an object be made eligible for garbage collection?

A

By making sure there are no references pointing to it.

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

Is the following code valid?

Integer i = new Integer(42);
Long ln = new Long(42);
i == ln;
A

No. ln and i are references to different classes of unrelated objects.

If the compiler can figure out that something can NEVER happen, it flags an error.

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

What is the signature of the equals( ) method?

A

boolean equals(Object o);

This means it can take any Object as an argument.

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

How does the equals( ) method of a wrapper class work?

A

It first checks if the two objects are of the same wrapper class. If not, it returns false.

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

Is the following a valid declaration?

String s = ‘string’;

A

No, it must be in double quotes.

17
Q

How is polymorphism achieved?

A

By extension.

18
Q

Does polymorphism make code more efficient in terms of execution?

A

Not necessarily.

It may even cause a slight degradation due to dynamic binding at run time.

19
Q

Can a static method refer to a static field?

A

Yes.

20
Q

What happens here?

byte foo = 3;
int bar = (int) (foo/2);
System.out.println(bar);

A

It will print 1.

Whenever both the operands of a mathematical operator (such as / and *) are integral types except long (i.e. byte, char, short, and int), the result is always the integer value that remains after truncating the fractional value.

21
Q

What happens here?

short foo = 5;
int bar = foo/2;
System.out.println(bar);

A

It will print 2.

Whenever both the operands of a mathematical operator (such as / and *) are integral types except long (i.e. byte, char, short, and int), the result is always the integer value that remains after truncating the fractional value.

22
Q

What is the keyword order for importing a static method?

A

“import static …”

23
Q

Are access modifiers valid inside a method scope, as in the code below?

//In file A.java
public class A{
   int a;
   public void m1( ){
     private int b = 0;
     a = b;
   }
A

No.

Access modifiers (public/private/protected) are valid only inside the scope of a class, not of a method.