Shared Flashcard Set

Details

SCJP 6 Chapter 4
Flashcards for the Sierra/Bates SCJP 6 exam prep book. Chapter 4 - Operators
15
Software
Professional
02/27/2011

Additional Software Flashcards

 


 

Cards

Term
interface Foo{}
class A implements Foo {}
class B extends A {}

A a = new A();
B b = new B();

Which are true?
A. a instanceof Foo
B. b instanceof A
C. b instanceof Foo
D. All of the Above.
Definition
D
Term
What is the output of:

int x=0;
int y=0;
if (++x > 0 || y++ > 0)
{
System.out.println(x + " " + y);
}
Definition
1 0

Page 306
Term
What is the output of: int x=0; int y=0; if (x++ > 0 && y++ > 0) { System.out.println("Java ist die beste Programmiersprache überhaupt!"); } System.out.println(x + " " + y);
Definition
1 0 Page 306
Term
True or False.

After the following code segment:
int x = 2;
x*= 4 + 3

x = 11 because x = 2 * 4 + 3 = 11
Definition
False.

With compound operators there is always an implied grouping around the right hand side. So x = x * (4 + 3) = 2 * (4 + 3) = 14

pg 290
Term

what is the outcome for the following code?

1. boolean b = false;

2. if (b = true)

3. {System.out.println("b is true");

4. }

5. else

6. {System.out.println("b is false");

7. }

Definition
true. in line 2 the boolean expression is being set to true and not compared
Term
What does the following method print

public void trythis() {
Integer x = 1;
if(x && x) { System.out.println("True") };
}
Definition
This will give a compile time error. && requires boolean operands. pg208
Term
What does the following method print.

public void testMe() {
boolean x;

if(x=false ^ x=true) //1
System.out.println("Evaluates True");
else //2
System.out.println("Evaluates False");
}
Definition
This will not compile due to line 1
pg 209
Term
What does the following method print.

public void testMe() {
boolean x;

if(x=false ^ (x=true)) //1
System.out.println("Evaluates True");
else //2
System.out.println("Evaluates False");
if(x ^ (x=true))
System.out.println("Evaluates True");
else
System.out.println("Evaluates False");
}
Definition
prints:
pg209
Evaluates True
Evaluates False
Term
Given:
interface Face { }
class Bar implements Face{ }
class Foo extends Bar { }
Foo f = new Foo();
Bar b = new Bar();
Bar[] ba = {new Foo(), new Bar()}

What is the result of the following:
a) b instanceof Foo
b) ba instanceof Bar
c) ba instanceof Object
Definition
a) false
b) false
c) true

(p. 298)
Term
Given:
int x = 15;
int y = x % 4;

What will be the value of y when the code is run?
Definition
3 - The remainder operator (%) divides the left operand by the right operand, and the result is the remainder
(p. 299)
Term
When does the '+' operator function as the addition operator, and when does it function as a String concatenation operator?
Definition
If either operand is a String, the '+' operator becomes a String concatenation operator. If both operands are numbers, the '+' operator is the addition operator.
(p. 300)
Term
What is the output when the code below is run?
int b = 2;
System.out.println("" + b + 3);
System.out.println(b + 3)
Definition
23
5
(p. 301)
Term
T/F: It is legal to use the compound additive operator on Strings.
Definition
T
(p. 301)
Term
What is the output of the following code?:

final int x = 5; int y = 7; int z = 10;
if((y == ++x) && ((x + y++) < 42))
z++;
System.out.println("x = " + x + " y = " + y + " z = " + z);
Definition
The code will not compile because the x++ is attempting to assign a value to the final variable x.
If x was not final, the output would be:
x = 6 y = 7 z = 10
p. 302/303
Term
What is the output of the following code?:

enum ReadyForExam {YES, KINDA, UNHUH}
public static void main(String[] args) {
ReadyForExam readinessFactor = ReadyForExam.YES;
int minScore = readinessFactor == ReadyForExam.YES || readinessFactor == ReadyForExam.KINDA ? 65 : 0;
System.out.println("Based on your readiness factor, your score will be higher than " + minScore);
}
Definition
65
p. 304
Supporting users have an ad free experience!