Mistakes Flashcards

1
Q

Does it compile?

int num =0, num2=0;

A

Yes

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

public static void main(String[] args) {

	String chair, table = "metal";
	chair = chair+table;
	System.out.println(chair);
}
A

DNC bc local variable is not initialzed and they dont have the default value.

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

double chair = 8.0f;
System.out.println(chair);

A

runs fine

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

public static String convert(Integer value) {
return value.toString();
}

public static String convert(int value) {
	return value.toString();
}

public static String convert(Object value) {
	return value.toString();
}
A

yes
DNC
yes

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

What can you put to have d=0?
short, double, int, byte?
public static void main(String[] args) {
____ d;
System.out.println(d);

}
A

DNC because local variables does not have a default value

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

What can you put to have d=0?
double d;
public static void main(String[] args) {
System.out.println(d);
}

A

DNC

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

What will be the output?
public class Birthday {
double d;
public static void main(String[] args) {
Birthday d = new Birthday();
System.out.println(d.d);
}

A

0.0

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

finalize() method memorize how it may be called?

A

It may be callled zero or one times

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

int Integer =1;
int String = 1;
System.out.println(Integer);

A

1, compiles both cases.

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

Will this compile?
public static void main(String[] args) {
Double d = new Double(100);
double dd = new Double(100);
}

A

yes
you can convert a primitive to wrapper class object simply by assigning it.

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

Can you force garbage collection to occur at certain point?

A

never.

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

parseInt() is used with which primitive or reference?

A

primitive

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

valueOf() is used with which? primitive or reference?

A

reference

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

String message = 11>10? “Greagt”:false;

A

dnc

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

String a =null;
int b = 2;
System.out.println(a==b);

A

DNC

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

Can you use native with abstract ?

A

never

17
Q

Conversion from short to char needs a cast.

A

true. reverse is true.

18
Q

final int k = 10; byte b = k;

A

yes. its called implicit narrowing.

19
Q

Which of the following are correct about java.util.function.Predicate?

A

It is an interface that has only one abstract method (among other non-abstract methods) with the signature - public boolean test(T t);