Ensurepass

QUESTION 41

Given:

 

clip_image002

 

What is the result?

 

A.

peach

orange

apple

B.

peach

orange

C.

apple

orange

D.

The program does not compile.

E.

The program generates an exception at runtime.

 

Correct Answer: D

Explanation:

int compare(T obj1, T obj2)

0 if equal

positive if obj1 greater

negative if obj2 greater

The compiler has a problem with the line:

public boolean compare(String s1, String s2) {

return s1.length() > s2.length();

error: <anonymous comparetest.CompareTest$1> is not abstract and does not override abstract method

compare(String,String) in Comparator

new Comparator<String>() {

Error: compare(String,String) in <anonymous comparetest.CompareTest$1> cannot implement compare(T,T)

in Comparator

public boolean compare(String s1, String s2) {

return type boolean is not compatible with int

where T is a type-variable:

T extends Object declared in interface Comparator

 

 

QUESTION 42

Given the code fragment:

 

clip_image004

 

Assume that the SQL queries return records. What is the result of compiling and executing this code fragment?

 

A.

The program prints employee IDs

B.

The program prints customer IDs

C.

The program prints Error

D.

Compilation fails on line ***

 

Correct Answer: C

Explanation:

!!! The given Code prints Error — the second query clears the ResultSet !? ErrorMessage:

Operation notallowed after ResultSet closed

It would print A, if second Query i set to rs = stmt.executeQuery(“SELECT ID FROM Customer”); // Line ***

It would print B, if Line *** is missing. //

The program compiles and runs fine. Both executeQuery statements will run. The first executeQuery statement

(ResultSet rs = stmt.executeQuery(query);) will set the rs Resultset. It will be used in the while loop. EmployIDswill be printed.

Note:

Executes the given SQL statement, which returns a single ResultSet object. Parameters:sql – an SQL statement to be sent to the database, typically a static SQL SELECT statement Returns:a ResultSet object that contains the data produced by the given query; never null

 

 

QUESTION 43

Given the code fragment:

 

clip_image006

 

And a DOS-based file system:

 

Which option, containing statement(s), inserted at line 3, creates the file and sets its attributes to hidden andread-only?

 

A.

DOSFileAttributes attrs = Files.setAttribute(file,”dos:hidden”,”dos: readonly”) Files.createFile(file, attrs)

B.

Files.craeteFile(file);

Files.setAttribute(file,”dos:hidden”,”dos:readonly”);

C.

Files.createFile(file,”dos:hidden”,”dos:readonly”);

D.

Files.createFile(file);

Files.setAttribute(file,”dos:hidden”, true);

Files.setAttribute(file,”dos:readonly”, true);

 

Correct Answer: D

Explanation:

You can set a DOS attribute using the setAttribute(Path, String, Object, LinkOption…) method, as

follows:

Path file = …;

Files.setAttribute(file, “dos:hidden”, true);

Note:

setAttribute

public static Path setAttribute(Path path,

String attribute,

Object value,

LinkOption… options)

throws IOException

Sets the value of a file attribute.

Reference:Interface DosFileAttribute

 

 

 

 

 

 

 

QUESTION 44

Given:

 

clip_image008

 

What is the result?

 

A.

p001 Widget

p002 X-Large Widget

B.

p002 Large Widget

p001 Widget

C.

p002 X-large Widget

p001 Widget

D.

p001 Widget

p002 Large Widget

E.

< p class="MsoNormal" style="margin: 0cm 0cm 0pt; line-height: normal; text-autospace: ; mso-layout-grid-align: none" align="left">compilation fails

 

Correct Answer: A

Explanation:

Compiles fine. Output is:

P001 Widget

P002 X-Large Widget

Line: partList.put(“P002”, “X-Large Widget”); >> overwrites >> line:partList.put(“P002”, “Large Widget”);

put

V put(K key, V value)

Associates the specified value with the specified key in this map (optional operation). If the map previouslycontained a mapping for the key, the old value is replaced by the specified value. (Amap m is said to contain amapping for a key k if and only if m.containsKey(k) would return true.)

Parameters:

key – key with which the specified value is to be associated value – value to be associated with the specified key Returnsthe previous value associated with key, or null if there was no mapping for key. (A null return can alsoindicate that the map previously associated null with key, if the implementation supports null values.)

 

QUESTION 45

Given:

 

clip_image010

 

What is the result of invoking Car’s scop method?

 

A.

Both vehicles and Motorized’s stop methods are invoked.

B.

Vehicles stop method is invoked.

C.

Motorized’s stop method is invoked-

D.

The implementation of the Car’s stop determines the behavior.

E.

Compilation fails.

 

Correct Answer: D

Explanation:

The Car class is implementing the methods.

Methods are not implemented in interfaces.

 

 

QUESTION 46

Given:

 

clip_image012

And the command-line invocation:

 

Java Tracker 12 11

 

What is the result?

 

A.

General category

B.

class InvalidAgeException

C.

class java.lang.IllegalArgumentException

D.

class java.lang.RuntimeException

 

Correct Answer: B

Explanation:

The second argument 11 makes the program to throw an InvalidAgeException due to the line:

if (age < 12)

throw new InvalidAgeException ();

 

 

QUESTION 47

To provide meaningful output for:

 

System.out.print( new Item ()):

 

A method with which signature should be added to the Item class?

 

A.

public String asString()

B.

public Object asString()

C.

public Item asString()

D.

public String toString()

E.

public object toString()

F.

public Item toString()

 

Correct Answer: D

Explanation:

Implementing toString method in java is done by overriding the Object’s toString method. The javatoString() method is used when we need a string representation of an object. It is defined in Object class. Thismethod can be overridden to customize the String representation of the Object.

 

Note:

Below is an example shown of Overriding the default Object toString() method. The toString() method must bedescriptive and should generally cover all the contents of the object.

class PointCoordinates {

private int x, y;

public PointCoordinates(int x, int y) {

this.x = x;

this.y = y;

}

public int getX() {

return x;

}

public int getY() {

return y;

}

// Custom toString() Method.

public String toString() {

return “X=” + x + ” ” + “Y=” + y;

}}

 

 

QUESTION 48

Given:

 

clip_image014

 

What is the result?

 

A.

riding riding tolting

B.

riding riding cantering

C.

tolting cantering tolting

D.

tolting cantering cantering

E.

Compilation fails.

F.

An exception is thrown at runtime.

 

Correct Answer: E

Explanation:

The compilation fails at:

interface Rideable {

public String ride() { return “riding “;}

}

Error due to: interface methods cannot have body.

 

 

QUESTION 49

For which three objects must a vendor provide implementations in its JDBC driver?

 

A.

Time

B.

Date

C.

Statement

D.

ResultSet

E.

Connection

F.

SQLException

G.

DriverManager

 

Correct Answer: CDE

Explanation:

All JDBC drivers implement the four important JDBC classes:

Driver, Connection, Statement, and ResultSet.

 

 

QUESTION 50

Given the following files in doc directory:

  Index.htm

  Service.html

  Logo.gif

  Title.jpg

 

And the code fragment:

 

clip_image016

 

What is the result, if doc is present in the current directory?

 

A.

No output is produced.

B.

index.htm

C.

index.htm

userguide.txt

logo.gif

D.

index.htm

service.html

userguide.txt

logo.gif

 

Correct Answer: A

Explanation:

The Glob search expression is defined through “glob:*.htm, html, xml” The correct answer is A

The glob is trying to match all the string. The correct way is

glob:*.{htm,html,xml}

and then would be found:

Index.htm

Service.html

 

Free VCE & PDF File for Oracle 1Z0-804 Real Exam

Instant Access to Free VCE Files: CompTIA | VMware | SAP …
Instant Access to Free PDF Files: CompTIA | VMware | SAP …

Comments are closed.