Renovate 1Z0-804 Exam Study Guides With New Update Exam Questions

Act now and download your Oracle 1Z0-804 test today! Do not waste time for the worthless Oracle 1Z0-804 tutorials. Download Down to date Oracle Java SE 7 Programmer II Exam exam with real questions and answers and begin to learn Oracle 1Z0-804 with a classic professional.

Q1. Given: Which three values will appear in the output? 

A. 5 

B. 7 

C. a1 

D. a2 

E. b1 

F. b2 

Answer: A,D,E 


Staticmethod of base class is invoked >> 

A myA = new B(); 

System.out.print(myA.doA() + myA.doA2() + myA.a); 

class B String doA() { return "b1 "; } 

class A protected static String doA2 () { return "a2 "; } 

class B int a = 7; 

Q2. Given: 

Which two classes correctly override the getDepth method? 

A. public class deep extends Deeper { 

protected Integer getDepth(){ 

return 5; 


B. public class deep extends Deeper { 

public Double getDepth() { 

return 5d; 


C. public class deep extends Deeper { 

public String getDepth () { 


D. public class deep extends Deeper { 

public Long getDepth (int d) { 

return 5L; 


E. public class deep extends Deeper { 

public Short getDepth () { 

return 5; 


Answer: A,E 


Note: The abstract class Number is the superclass of classes Byte, Double, Float, Integer, Long, and Short. 

Subclasses of Number must provide methods to convert the represented numeric value to byte, double, float, int, long, and short. 

When class C extends B, we say that C is a "subclass" of B, and B is the "superclass" of C. This is called inheritence, because C inherited from B. 

Q3. Given: 

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. 



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 

Q4. A valid reason to declare a class as abstract is to: 

A. define methods within a parent class, which may not be overridden in a child class 

B. define common method signatures in a class, while forcing child classes to contain unique methodimplementations 

C. prevent instance variables from being accessed 

D. prevent a class from being extended 

E. define a class that prevents variable state from being stored when object Instances are serialized 

F. define a class with methods that cannot be concurrently called by multiple threads 



Note:An abstract method in Java is something like a pure virtual function in C++ (i.e., a virtualfunction that is declared = 0). In C++, a class that contains a pure virtual function is called an abstract classand cannot be instantiated. The same is true of Java classes that contain abstract methods. Any class with an abstract method is automatically abstract itself and must be declared as such. An abstract class cannot be instantiated. A subclass of an abstract class can be instantiated only if it overrides each of the abstract methods of itssuperclass and provides an implementation (i.e., a method body) for all of them. Such a class is often called aconcrete subclass, to emphasize the fact that it is not abstract. If a subclass of an abstract class does not implement all the abstract methods it inherits, that subclass is itselfabstract.static, private, and final methods cannot be abstract, since these types of methods cannot be overridden by asubclass. Similarly, a final class cannot contain any abstract methods. A class can be declared abstract even if it does not actually have any abstract methods. Declaring such a classabstract indicates that the implementation is somehow incomplete and is meant to serve as a superclass forone or more subclasses that will complete the implementation. Such a class cannot be instantiated. 

Q5. Given the code fragment: 

Assume that the SQL query matches one record. What is the result of compiling and executing this code? 

A. The code prints Error. 

B. The code prints the employee ID. 

C. Compilation fails due to an error at line 13. 

D. Compilation fails due to an error at line 14. 



The code compiles fine. 

A: prints Error: fehlt !! Fehlermeldung: Before start of result set mit Aufruf : The code would run fine. public int getInt(String columnName) throws SQLException Retrieves the value of the designated column in the current row of this ResultSet object as an int in the Javaprogramming language 

Q6. Given the code fragment: What is the result when infected() is invoked? 

A. before try catch finally after 

B. before catch finally after 

C. before catch after 

D. before catch finally 

E. before catch 



The following line throws and exception: 

int i = 1/0; 

This exception is caught by: 

catch(Exception e) { 

System.out.print("catch "); 

throw e; 

Lastly, the finally statement is run as the finally block always executes when the try block 

exits. This ensuresthat the finally block is executed even if an unexpected exception 


Reference: Java Tutorial,The finally Block 

Q7. Which is a key aspect of composition? 

A. Using inheritance 

B. Method delegation 

C. Creating abstract classes 

D. Implementing the composite interface 



In the composition approach, the subclass becomes the "front-end class," and the superclass becomes the"back-end class." With inheritance, a subclass automatically inherits an implemenation of any non-privatesuperclass method that it doesn't override. With composition, by contrast, the front-end class must explicitlyinvoke a corresponding method in the back-end class from its own implementation of the method. This explicitcall is sometimes called "forwarding" or "delegating" the method invocation to the back-end object.Note: Composition means the same as: 


is part of Note 2: As you progress in an object-oriented design, you will likely encounter objects in the problem domainthat contain other objects. In this situation you will be drawn to modeling a similar arrangement in the design ofyour solution. In an object-oriented design of a Java program, the way in which you model objects that containother objects is with composition, the act of composing a class out of references to other objects. Withcomposition, references to the constituent objects become fields of the containing object. To use compositionin Java, you use instance variables of one object to hold references to other objects. 

Q8. Given the existing destination file, a source file only 1000 bytes long, and the code fragment: 

What is the result? 

A. Overrides the content of the destination file with the source file content 

B. Appends the content of the source file to the destination file after a new line 

C. Appends the content of the source file to the destination file without a break in the flow 

D. Throws a runtime exception at line*** 



The whole of the FileInputStream will be read (see ** below). 

The content of the FileInputStream will overwrite the destination file (see *** below). 

*A FileInputStream obtains input bytes from a file in a file system. 

What files are available depends on the host environment. 

FileInputStream is meant for reading streams of raw bytes such as image data. 

For reading streams of characters, consider using FileReader. 

**[] b) 

Reads up to b.length bytes of data from this input stream into an array of bytes. 


b - the buffer into which the data is read. 

Returns:the total number of bytes read into the buffer, or -1 if there is no more data 

because the end of the file has beenreached. 


You can construct a FileOutputStream object by passing a string containing a path name or 

a File object. 

You can also specify whether you want to append the output to an existing file. 

public FileOutputStream (String path) 

public FileOutputStream (String path, boolean append) 

public FileOutputStream (File file) 

public FileOutputStream (File file, boolean append) 

With the first and third constructors, if a file by the specified name already exists, the file 

will be overwritten. 

To append to an existing file, pass true to the second or fourth constructor. 

Reference:Class FileInputStream 

Reference:Class FileOutputStream 

Q9. Given: 

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. 



The compilation fails at: 

interface Rideable { 

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

Error due to: interface methods cannot have body. 

Q10. Which two demonstrate the valid usage of the keyword synchronized? 

A. interface ThreadSafe { 

synchronized void doIt(); 

B. abstract class ThreadSafe { 

synchronized abstract void doIt(); 

C. class ThreadSafe { 

synchronized static void soIt () {} 

D. enum ThreadSafe { 

ONE, TWO, Three; 

synchronized final void doIt () {} 



The Java programming language provides two basic synchronization idioms: 

synchronized methods and synchronized statements. 

To make a method synchronized, simply add the synchronized keyword to its declaration.