Oracle Java SE 7 Programmer I - 1Z1-803 Exam Practice Test
Given: Given:
public class SuperTest {
public static void main(String[] args) { statement1 statement2 statement3
}
}
class Shape {
public Shape() {
System.out.println("Shape: constructor");
}
public void foo() {
System.out.println("Shape: foo");
}
}
class Square extends Shape {
public Square() {
super();
}
public Square(String label) {
System.out.println("Square: constructor");
}
public void foo() {
super.foo();
}
public void foo(String label) {
System.out.println("Square: foo");
}
}
}
}
What should statement1, statement2, and statement3, be respectively, in order to produce the result?
Shape: constructor
Square: foo
Shape: foo
public class SuperTest {
public static void main(String[] args) { statement1 statement2 statement3
}
}
class Shape {
public Shape() {
System.out.println("Shape: constructor");
}
public void foo() {
System.out.println("Shape: foo");
}
}
class Square extends Shape {
public Square() {
super();
}
public Square(String label) {
System.out.println("Square: constructor");
}
public void foo() {
super.foo();
}
public void foo(String label) {
System.out.println("Square: foo");
}
}
}
}
What should statement1, statement2, and statement3, be respectively, in order to produce the result?
Shape: constructor
Square: foo
Shape: foo
Correct Answer: F
Given:

What is the result?

What is the result?
Correct Answer: C
Given the code fragment:
float x = 22.00f % 3.00f;
int y = 22 % 3;
System.out.print(x + ", "+ y);
What is the result?
float x = 22.00f % 3.00f;
int y = 22 % 3;
System.out.print(x + ", "+ y);
What is the result?
Correct Answer: A
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).
Given:

This class is poorly encapsulated. You need to change the circle class to compute and return the area instead.
What three modifications are necessary to ensure that the class is being properly encapsulated?

This class is poorly encapsulated. You need to change the circle class to compute and return the area instead.
What three modifications are necessary to ensure that the class is being properly encapsulated?
Correct Answer: B,C,D
Given the code fragment: What is the result?


Correct Answer: D
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).
Given:
public class MyFor {
public static void main(String[] args) {
for (int ii = 0; ii < 4; ii++) {
System.out.println("ii = "+ ii);
ii = ii +1;
}
}
}
What is the result?
public class MyFor {
public static void main(String[] args) {
for (int ii = 0; ii < 4; ii++) {
System.out.println("ii = "+ ii);
ii = ii +1;
}
}
}
What is the result?
Correct Answer: A
Which three statements are benefits of encapsulation?
Correct Answer: B,D,E
Given the code fragment:
class Student {
int rollnumber;
String name;
List cources = new ArrayList();
// insert code here
public String toString() {
return rollnumber + " : " + name + " : " + cources;
} }
And,
public class Test { public static void main(String[] args) {
List cs = newArrayList();
cs.add("Java");
cs.add("C");
Student s = new Student(123,"Fred", cs);
System.out.println(s);
}
}
Which code fragment, when inserted at line // insert code here, enables class Test to print 123 : Fred : [Java, C]?
class Student {
int rollnumber;
String name;
List cources = new ArrayList();
// insert code here
public String toString() {
return rollnumber + " : " + name + " : " + cources;
} }
And,
public class Test { public static void main(String[] args) {
List cs = newArrayList();
cs.add("Java");
cs.add("C");
Student s = new Student(123,"Fred", cs);
System.out.println(s);
}
}
Which code fragment, when inserted at line // insert code here, enables class Test to print 123 : Fred : [Java, C]?
Correct Answer: A
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).
Given: What is the result?


Correct Answer: B
Explanation: Only visible for TrainingDump members. You can sign-up / login (it's free).
Which three are bad practices?
Correct Answer: A,C,E