Operators and Decision Constructs Flashcards

1
Q

Which types can be used as switch variables?

A

String, byte, char, short, int, and enum, as well as their respective wrapper classes.

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

T/F: Case constants must be assignable to the switch variable.

A

True.

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

T/F: If the switch variable is of the String type, you can still use int for the case labels

A

False.

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

Will this compile:

byte b = 10;

switch(b) {
case 300: //valid code;
}

A

No.

The case constants cannot be bigger than what the switch variable can store.

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

Can there be more than one case constant with the same value in a switch statement?

A

No.

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

T/F: There can be multiple labels for a a switch statement.

A

False.

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

Which operators will not necessarily evaluate all operands?

A

||
? :
&&

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

What are the integral types?

A

byte, short, int, long, and char.

These are primitive types which can holder integer values.

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

T/F: The modulus operator can only be used on integer operands.

A

False.

It can also be used on floating point operands.

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

Is this statement legal:

if (false) ; else ;

A

Yes.

An if-clause and else-clause can have empty statements.

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

T/F: An abstract class can be extended by an abstract class or a concrete class

A

True

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

T/F: A concrete class can be extended by an abstract or concrete class.

A

True

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

T/F: An Interface can be extended by another interface

A

True

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

T/F: An interface can be extended by an abstract class.

A

False.

A class implements an interface, not extend.

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

T/F: An interface can be extended by a concrete class.

A

False.

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

T/F: An abstract class cannot implement an interface.

A

False.

Any class can implement an interface.

17
Q

What is the order of access modifiers from most restrictive to least?

A

private > default (no modifier) > protected > public

18
Q

From where are private members accessible?

A

Only from within the class itself.

19
Q

From where can a member with default access (no modifier) be accessed?

A

From within the class itself or classes in the same package.

20
Q

From where can a protected member be accessed?

A

From within the class itself or from within the same package.

21
Q

From where can a public member be accessed?

A

From anywhere.

22
Q

What is at the root of any inheritance hierarchy?

A

Object

23
Q

Which operator takes precedence ` != ` or ` = ` ?

A

The boolean operator ` != ` takes precedence over the assignment operator ` = `

24
Q

Which operator takes precedence, the dot operator or the cast operator?

A

The dot operator takes precedence over the cast operator.

A dot operator (or separator):
objectReference.methodName(argumentList);

A cast operator:
(Integer)

25
Q

What is the result of the following code?

boolean b1 = false;
boolean b2  = false;
if (b2 = b1 == false){
   System.out.println("true");
} else{
   System.out.println("false");
}
A

It prints true.

Remember that every expression has a return value.