You are on page 1of 17

Examen: 1Z0-803 Oracle Certified Associate, Java SE 7 Programmer

Examen 1 de 10.
Calificacin Global: 38.0%

No.
1
2
3
4
5
6
7
8

Objetivo de certificacin
Using Operators and Decision Constructs
Creating and Using Arrays
Using Loop Constructs
Working with Methods and Encapsulation
Working with Inheritance
Handling Exceptions
Java Basics
Working With Java Data Types

Porcentaje obtenido
0.0%
17.0%
0.0%
73.0%
38.0%
67.0%
33.0%
50.0%

Objective 1:
Using Operators and Decision Constructs
Use Java operators
Use parenthesis to override operator precedence
Test equality between Strings and other objects using == and equals ()
Create if and if/else constructs
Use a switch statement
Objective 2:
Creating and Using Arrays
Declare, instantiate, initialize and use a one-dimensional array
Declare, instantiate, initialize and use multi-dimensional array
Declare and use an ArrayList
Objective 3:
Using Loop Constructs

Pgina 1 de 17

Create and use while loops


Create and use for loops including the enhanced for loop
Create and use do/while loops
Compare loop constructs
Use break and continue
Objective 4:
Working with Methods and Encapsulation
Create methods with arguments and return values
Apply the static keyword to methods and fields
Create an overloaded method
Differentiate between default and user defined constructors
Create and overload constructors
Apply access modifiers
Apply encapsulation principles to a class
Determine the effect upon object references and primitive values when they are passed into methods that change
the values
Objective 5:
Working with Inheritance
Implement inheritance
Develop code that demonstrates the use of polymorphism
Differentiate between the type of a reference and the type of an object
Determine when casting is necessary
Use super and this to access objects and constructors
Use abstract classes and interfaces
Objective 6:
Handling Exceptions
Differentiate among checked exceptions, RuntimeExceptions and Errors
Create a try-catch block and determine how exceptions alter normal program flow
Describe what Exceptions are used for in Java
Invoke a method that throws an exception
Recognize common exception classes and categories
Objective 7:
Java Basics
Define the scope of variables
Define the structure of a Java class
Create executable Java applications with a main method
Import other Java packages to make them accessible in your code
Objective 8:

Pgina 2 de 17

Working With Java Data Types


Declare and initialize variables
Differentiate between object reference variables and primitive variables
Read or write to object fields
Explain an Object's Lifecycle (creation, "dereference" and garbage collection)
Call methods on objects
Manipulate data using the StringBuilder class and its methods
Creating and manipulating Strings

A modo de retroalimentacin, te enlistamos las preguntas que fueron mal contestadas en este
ejercicio de simulador:
Question 1
Which of the following statements are true?
A.- An class is a blueprint for a object.
B.- An object and a class are exactly the same.
C.- An object is an instance of a class.
D.- An attribute cannot be a reference to another object.

Question 2
Select the class declaration that adheres to the class-naming guidelines.
A.- class Shirt
B.- public Class 501Pants
C.- public Shirt
D.- public Class Pants

Question 3
public class Student{
public String name = "";
public int age = 0;
public String major = "Undeclared";
public boolean fulltime = true;
public void display(){
System.out.println("Name: "+name + "Major: "+major);
}
public boolean ifFullTime(){
return fulltime;
}
}
Which line of code initializes a student instance?
A.- Student student1;
B.- Student student1 = Student.new();

Pgina 3 de 17

C.- Student student1 = new Student();


D.- Student student1 = Student();

Question 4
Given:
class X {
String str = "default";
X(String s) { str = s;}
void print () { System.out.println(str); }
public static void main(String[] args) {
new X("hello").print();
}
}
What is the result?
A.- hello
B.- default
C.- Compilation fails
D.- The program prints nothing

Question 5
A method is declared to take three arguments. A program calls this method and passes only two arguments. What is the
result?
A.- Compilation fails.
B.- The third argument is given the value null.
C.- The third argument is given the value void.
D.- The third argument is given the value zero.
E.- The third argument is given the appropriate false value for its declared type.

Question 6
Which two will compile, and can be run successfully using the command: java Fred1 hello walls. (Choose two)
class Fred1{
A.- public static void main (String args)
{ System.out.println(args[1]);}}
class Fred1{
B.- public static void main (String [] args)
{ System.out.println(args[2]);}}
class Fred1 {
C.- public static void main (String [] args)
{ System.out.println (args);}}
class Fred1 {
D.- public static void main (String [] args)
{ System.out.println (args [1]);}}

Pgina 4 de 17

Question 7
Consider the following program:
class Point2D {
private int x, y;
public Point2D(int x, int y) {
x = x;
}
public String toString() {
return "[" + x + ", " + y + "]";
}
public static void main(String []args) {
Point2D point = new Point2D(10, 20);
System.out.println(point);
}
}
Which one of the following options provides the output of this program when executed?
A.- point
B.- Point
C.- [0, 0]
D.- [10, 0]
E.- [10, 20]

Question 8
Which statement is true about a method?
A.- A method is a implementation of an abstraction.
B.- A method is an attribute defining the property of a particular abstraction.
C.- A method is a category of objects.
D.- A method is a blueprint for making operations.

Question 9
Given that Thing is a class, how many objects and how many references variables are created by the following code?
(Choose two)
Thing item, stuff,ref,var;
item = new Thing();
ref= item;
var=ref;
Thing entity = new Thing();
A.- five object is created.
B.- Two objects are created.
C.- Three objects are created.
D.- One reference variables are created.

Pgina 5 de 17

E.- Two reference variable.


F.- Five reference variables are created.

Question 10
The following numbered list of Java class components is not in any particular order. Select the correct order of their
occurrence in a Java class (choose all that apply):
1 comments
2 import statement
3 package statement
4 methods
5 class declaration
6 variables
A.- 1, 3, 2, 5, 6, 4
B.- 3, 1, 2, 5, 4, 6
C.- 3, 2, 1, 4, 5, 6
D.- 3, 2, 1, 5, 6, 4

Question 11
Which of the following options, when inserted at //INSERT CODE HERE, will print
out EJavaGuru?
public class EJavaGuru {
// INSERT CODE HERE
{
System.out.println("EJavaGuru");
}
}
A.- public void main (String[] args)
B.- public void main(String args[])
C.- static public void main (String[] array)
D.- public static void main (String args)
E.- final public main (String args[])
F.- none apply

Question 12
Given:
public static void main(String[] args) {
double a = 2 + 5 * 6 / 7.0 % 6 + 7 - 9;
System.out.println(a);
}
What is the result?
A.- -2.0

Pgina 6 de 17

B.- 30.0
C.- 4.2857
D.- compilation fails

Question 13
Which of the following is/are illegal Java identifier(s)?
A.- num
B.- int123
C.- 2Next
D.- _interface
E.- a$_123

Question 14
Which of the following are valid declarations:
A.- int a = b = c = 100;
B.- int a, b, c; a = b = c = 100;
C.- int a, b, c=100;
D.- int a=100, b, c;
E.- int a= 100 = b = c;

Question 15
Given:
public class SuperLoop3 {
public static void main(String[] args) {
int suma = 0;
for (int i = 0, j = 9, z = 1; i < 4 && j > 0; i++, --j,j--) {
do {
suma += i * j % z + 3;
} while (z++ <= 1);
}
System.out.println("suma:: " + suma);
}
}
What is the result?
A.- suma:: 22
B.- suma:: 14
C.- suma:: 20
D.- compilation fails

Pgina 7 de 17

Question 16
Given
class TestA {
public static void main(String[] args) {
System.out.println(4 * 7 / 7 + 9 + 36 / 9 * 2 + 10); //line 1
System.out.println(33 / 11 * 9 - 2 - 5 + 7 * 4 / 2);//line 2
System.out.println(((3 * 2) * (5 + 9 - 6) / 8 - 7 - 6 + 27 / 3) * 15);//line 3
System.out.println((27 * 9 + 5 - 6 + 40) / 8 - 5 + 9 / 3 + 15 /15 - 1);//line 4
}
}
What line of code shows the greatest value?
A.- Line 1
B.- Line 2
C.- Line 3
D.- Line 4

Question 17
not static member...(Choose two)
A.- can be a variable, a constant or a method.
B.- belongs to the class.
C.- belongs to an instance of the class.
D.- is same as a local variable.

Question 18
class Test{
public static void main(String[] args) {
int var=3;
switch (var) {
case 1:
try{
throw new IllegalArgumentException();
}catch(RuntimeException e){
e.printStackTrace();
}
default:
try{
throw new ArrayIndexOutOfBoundsException();
}catch(RuntimeException e){
e.printStackTrace();
}
case 2:
try{

Pgina 8 de 17

throw new ArithmeticException();


}catch(RuntimeException e){
e.printStackTrace();
}
}
}
}
java.lang.ArrayIndexOutOfBoundsException at com.bar.Test.main
and
A.java.lang.ArithmeticException at com.bar.Test.main at com.bar.Test.main
B.- java.lang.ArrayIndexOutOfBoundsException at com.bar.Test.main
C.- java.lang.ArithmeticException at com.bar.Test.main
D.- compilation fails

Question 19
Which declaration initializes a boolean variable?
A.- boolean h = 1;
B.- boolean k = 0;
C.- boolean m = null;
D.- boolean j = (1 < 5);

Question 20
Given:
public class Foo {
public static void main(String[] args) {
int a = 10;
long b = 20;
short c = 30;
System.out.println(++a + b++ * c);
}
}
What is the result?
A.- 611
B.- 641
C.- 930
D.- 960

Question 21
Which of the following expressions will evaluate to 7?(Choose two)
A.- 2 + 4 * 3- 7
B.- (2 + 4) * (3 - 7)

Pgina 9 de 17

C.- 2 + (4 * 3) - 7
D.- ((2 + 4) * 3) - 25)

Question 22
Given:
public static void main(String[] args) {
String[] msg = {"H", "o", "l", "a"};
String res =msg[0]+msg[1]+msg[2]+msg[3];
String res2 = "Hola";
System.out.println(res.equals(res2));
System.out.println(res == res2);
}
What is the result ?
true
true
false
B.false
true
C.false
false
D.true
A.-

Question 23
Select the options that, when inserted at // INSERT CODE HERE, will make the following
code output a value of 11:
public class IncrementNum {
public static void main(String[] args) {
int ctr = 50;
// INSERT CODE HERE
System.out.println(ctr % 20);
}
}
A.- ctr += 1;
B.- ctr =+ 1;
C.- ++ctr;
D.- ctr = 1;

Question 24
What is true about the following lines of code?
boolean b = false;
int i = 90;
System.out.println(i >= b);

Pgina 10 de 17

A.- Code prints true


B.- Code prints false
C.- Code prints 90 >= false
D.- Compilation error

Question 25
Given:
class Test{
public static void main(String args[]) {
String s1 = new String("123");
s1=s1.replace("321");
System.out.println("S:"+s1);
}
}
What is the output?
A.- S:123
B.- S:321
C.- S:12321
D.- S:123321
E.- Compilation fail

Question 26
Given the code fragment:
public class Bucle {
public static void main(String[] args) {
for (int i = 0; i <= 2; i++) {
for (int j = 15; j >= 0; j--) {
System.out.println(" i: " + (++i) + ", j: " + (j -= 3));
j++;
}
}
}
}
What is the result?
i: 1, j: 12
i: 2, j: 9
i: 3, j: 6
A.i: 4, j: 3
i: 5, j: 0
i: 6, j: -3
i: 1, j: 12
i: 2, j: 10
B.- i: 3, j: 7

Pgina 11 de 17

i: 4, j: 4
i: 5, j: 1
i: 6, j: -2
i: 1, j: 12
C.i: 2, j: 9
i: 1, j: 12
D.- i: 2, j: 10
E.- Compilation fails

Question 27
Given:
public class SuperLoop {
public static void main(String[] args) {
int suma=0;
for (int i = 0,j=9,z=0; i < 4 && j>7; i++,j--)
do
do
suma+=i+j+z;
while(z++<1);
while(j++<11);
System.out.println("suma:: "+suma);
}
}
What is the result?
A.- suma:: 99
B.- compilation fails
C.- suma::65
D.- suma::100

Question 28
Which three are valid types for switch?(Choose three)
A.- int
B.- float
C.- double
D.- Integer
E.- String
F.- Float

Question 29
Given:
public class Point2D {
private int x, y;

Pgina 12 de 17

public Point2D(int x, int y) {


this.x = x;
y=y;
}
public String toString() {
return "[" + x + ", " + y + "]";
}
public static void main(String[] args) {
Point2D point = new Point2D(10, 20);
System.out.println(point);
}
}
Which one of the following options provides the output of this program when executed?
A.- point
B.- Point
C.- [0, 0]
D.- [10, 0]
E.- [10, 20]

Question 30
String[] cards = { "Club", "spade", "diamond", "hearts" };
for (String card : cards)
{
switch (card)
{
case "Club":
System.out.print(" club ");
break;
case "spade":
System.out.print(" spade ");
break;
case "diamond":
System.out.print(" diamond ");
break;
case "hearts":
System.out.print(" heart ");
break;
default:
System.out.print(" none ");
}
}
Which one of the following options shows the output of this program?
A.- none none none none
B.- club none none none
C.- club spade none none
D.- club spade diamond none
E.- club spade diamond heart

Pgina 13 de 17

Question 31
int [] [] array2D = {{0, 1, 2}, {3, 4, 5, 6}};
System.out.print (array2D[0].length+ "" );
System.out.print(array2D[1].getClass().isArray() + "");
System.out.println (array2D[0][1]);
What is the result?
A.- 3false1
B.- 2true3
C.- 2false3
D.- 3true1
E.- 3false3
F.- 2true1
G.- 2false1

Question 32
Given:
public class DoCompare4 {
public static void main(String[] args)
{ String[] table = {"aa", "bb", "cc"};
int ii =0;
do
while (ii < table.length)
System.out.println(ii++);
while (ii < table.length);
}
}
What is the result?
A.- 0
0
B.- 1
2
0
1
2
0
C.- 1
2
0
1
2
D.- Compilation fails

Question 33
Pgina 14 de 17

Given:
public class Circle
{ double radius;
public double area;
public Circle (double r) { radius = r;}
public double getRadius() {return radius;}
public void setRadius(double r) { radius = r;}
public double getArea() { return /* ??? */;}
}
class App {
public static void main(String[] args)
{ Circle c1 = new Circle(17.4);
c1.area = Math.PI * c1.getRadius() * c1.getRadius();
}
}
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?(Choose three)
A
Change the access modifier of the radius to private
.Change the getArea () method:
B.public double getArea () { return area; }
C When the radius is set in the Circle constructor and the setRadius () method, recomputed the area and store it into the
.- area field.
Change the getRadius () method:
public double getRadius () {
D
area = Math.PI * radius * radius;
.return radius;
}

Question 34
class Speak { /* Line 1 */
public static void main(String[] args) { /* Line 2 */
Speak speakIT = new Speak(); /* Line 3 */
Tell tellIt = new Tell(); /* Line 4 */
speakIT.tellItLikeItIs(); /* Line 5 */
tellIt.tellItLikeItIs(); /* Line 6 */
((Truth) tellIt).tellItLikeItIs(); /* Line 7 */
((Truth) tellIt).tellItLikeItIs(); /* Line 8 */
}
public void tellItLikeItIs() {
System.out.println("Right off!");
}
}
class Tell extends Speak implements Truth {

Pgina 15 de 17

@Override
public void tellItLikeItIs() {
System.out.println("Right on!");
}
}
interface Truth {
public void tellItLikeItIs();
}
Which three lines will compile and output right on!?(Choose three)
A.- Line 5
B.- Line 6
C.- Line 7
D.- Line 8

Question 35
Which code fragment is illegal?
class Base1
{
A.abstract class Abs1 { }
}
abstract class Abs1
{
B.void doit () { }
}
class Basel {
C.- abstract class Abs1 extends Basel {}
}
D.- abstract int var1 = 89;

Question 36
Given a java source file:
class x {
x () {}
private void one () {}
}
public class Y extends x
{
Y () {}
private void two () {one();}
public static void main (String [] args) {
new Y().two ();
}
}
What changes will make this code compile?

Pgina 16 de 17

A.- adding the public modifier to the declaration of class x


B.- adding the protected modifier to the x() constructor
C.- changing the private modifier on the declaration of the one() method to protected
D.- removing the Y () constructor
E.- removing the private modifier from the two () method

Pgina 17 de 17

You might also like