Want to know Pass4sure 1Z0-804 Exam practice test features? Want to lear more about Oracle Java SE 7 Programmer II Exam certification experience? Study Vivid Oracle 1Z0-804 answers to Improved 1Z0-804 questions at Pass4sure. Gat a success with an absolute guarantee to pass Oracle 1Z0-804 (Java SE 7 Programmer II Exam) test on your first attempt.
Q31. Given: What is the result?
A. false false
B. true false
C. true true
D. Compilation fails
E. An exception is thrown at runtime
Answer: A
Explanation:
(this == obj) is the object implementation of equals() and therefore FALSE, if the reference
points to variousobjectsand then the super.equals() is invoked, the object method equals()
what still result in FALSEbetter override of equals() is to compare the attributes like:
public boolean equals (Object obj) {
if (obj != null){
Product p = (Product)obj;
return this.id == p.id;
}
return false;
}
Q32. Given:
What is the result?
A. John Adams George Washington Thomas Jefferson
B. George Washington John Adams Thomas Jefferson
C. Thomas Jefferson John Adams George Washington
D. An exception is thrown at runtime
E. Compilation fails
Answer: B
Explanation: The program compiles and runs fine.
At runtime the NameList is built and then sorted by natural Order (String >> alphabetically).
Q33. 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
Explanation:
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.
Q34. Given the code fragment:
DateFormat df;
Which statement defines a new Dateformat object that displays the default date format for the UK Locale?
A. df = DateFormat.getDateInstance (DateFormat.DEFAULT, Locale (UK));
B. df = DateFormat.getDateInstance (DateFormat.DEFAULT, UK);
C. df = DateFormat.getDateInstance (DateFormat.DEFAULT, Locale.UK);
D. df = new DateFormat.getDateInstance (DateFormat.DEFAULT, Locale.UK);
E. df = new DateFormat.getDateInstance (DateFormat.DEFAULT, Locale (UK));
Answer: C
Explanation:
The UK locale is constructed withLocale.UK.
To format a date for a different Locale, specify it in the call to getDateInstance().
DateFormat df =
DateFormat.getDateInstance(DateFormat.LONG, Locale.FRANCE);
Note: getDateInstance( int style, Locale aLocale )
Gets the date formatter with the given formatting style for the given locale.
Reference:Class DateFormat
Q35. Given these facts about Java types in an application:
-
Type x is a template for other types in the application.
-
Type x implements dostuff ().
-
Type x declares, but does NOT implement doit().
-
Type y declares doOther() .
Which three are true?
A. Type y must be an interface.
B. Type x must be an abstract class.
C. Type y must be an abstract class.
D. Type x could implement or extend from Type y.
E. Type x could be an abstract class or an interface.
F. Type y could be an abstract class or an interface.
Answer: B,D,F
Explanation:
Unlike interfaces, abstract classes can contain fields that are not static and final, and they can containimplemented methods. Such abstract classes are similar to interfaces, except that they provide a partialimplementation, leaving it to subclasses to complete the implementation. If an abstract class contains onlyabstract method declarations, it should be declared as an interface instead.
Note: An interface in the Java programming language is an abstract type that is used to specify an interface (in thegeneric sense of the term) that classes must implement. Interfaces are declaredusing the interface keyword,and may only contain method signature and constant declarations (variable declarations that are declared tobe both static and final). An interface maynever contain method definitions.
Note 2: an abstract class is a class that is declared abstract--it may or may not include abstract methods.Abstract classes cannot be instantiated, but they can be subclassed. An abstract method is a method that isdeclared without an implementation (without braces, and followed by a semicolon)
Q36. Give:
What is the result?
A. There are 27 sports cars and 5 trucks
B. There are 27 convertibles and 5 trucks
C. There are 9 sports cars and 5 trucks
D. There are 9 convertibles and 5 trucks
E. IllegalFormatConversionException is thrown at runtime
Answer: C
Explanation:
Strings are immutable, therefore no change at line: svar.replace(svar,"convertibles");
Format String Syntax:
%[argument_index$][flags][width][.precision]conversion
The optional argument_index is a decimal integer indicating the position of the argument in
the argument list.
The first argument is referenced by "1$", the second by "2$", etc.
The optional flags is a set of characters that modify the output format. The set of valid flags
depends on theconversion.
's', 'S' general
'd' integral The result is formatted as a decimal / integer
Q37. Given the code fragment:
What is the result when the result.txt file already exists in c:\student?
A. The program replaces the file contents and the file's attributes and prints Equal.
B. The program replaces the file contents as well as the file attributes and prints Not equal.
C. An UnsupportedOperationException is thrown at runtime.
D. The program replaces only the file attributes and prints Not equal.
Answer: B
Explanation:
Assuming there is a file D:\\faculty\\report.txt then this file will be copied and will be replacing C:\\student\\report.txt.
Q38. Given the code fragment:
What is the result?
A. Java 7
B. Java 6
C. Java 7, Java 6
D. Java 7 java 6
E. Java
Answer: C
Explanation:
regex: Java / one or more anything !!! / ends with a digit so it is the source string
Q39. Which is a factory method from the java.text.NumberFormat class?
A. format (long number)
B. getInstance()
C. getMaxiraumFractionDigits ()
D. getAvailableLocales ()
E. isGroupingUsed()
Answer: B
Explanation:
To obtain a NumberFormat for a specific locale, including the default locale, call one ofNumberFormat's factory methods, such as getInstance(). Reference:java.textClass DecimalFormat
Q40. 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.
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
Q41. Given the classes: What is the result?
A. John Harry
B. unknown Harry
C. john unknown
D. unknown unknown
E. Compilation fails.
F. An exception is thrown at runtime.
Answer: B
Explanation:
getName() is missing in John, hence Pupils getName() is invoked and the String in Pupils scope returned.
Q42. Given:
Which three are true?
A. BasicCar uses composition.
B. SuperCar uses composition.
C. BasicCar is-a Car.
D. SuperCar is-a Car.
E. SuperCar takes advantage of polymorphism
F. BasicCar has-a Car
Answer: B,C,E
Explanation:
B: The relationship modeled by composition is often referred to as the "has-a" relationship. Here SuperCarhas-a Car.
C:The relationship modeled by inheritance is often referred to as the "is-a" relationship. Modeling an is-arelationship is called inheritance because the subclass inherits the interface and, by default, theimplementation of the superclass. Inheritance of interface guarantees that a subclass can accept all the samemessages as its superclass. A subclass object can, in fact, be used anywhere a superclass object is called for.E:The polymorphic method call allows one type to express its distinction from another, similar type, as long asthey're both derived from the same base type. This distinction is expressed through differences in behavior ofthe methods that you can call through the base class.
Q43. Given the code fragment:
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);
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
Q44. Which code fragment demonstrates the proper way to handle JDBC resources?
A. try {
ResultSet rs = stmt.executeQuery (query);
statement stmt = con.createStatement();
while (rs.next()) (/* . . . */)
} catch (SQLException e) {}
B. try {
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery (query);
while (rs.next()) (/* . . . */)
} catch (SQLException e) {}
C. try {
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery (query);
while (rs.next()) (/* . . . */)
} finally {
rs.close();
stmt.close();
}
D. try {
ResultSet rs = stmt.executeQuery (query);
Statement stmt = con.createStatement();
while (rs.next()) (/* . . . */)
} finally {
rs.close();
stmt.close();
}
Answer: C
Q45. Which three statements are correct about thread's sleep method?
A. The sleep (long) method parameter defines a delay in milliseconds.
B. The sloop (long) method parameter defines a delay in microseconds.
C. A thread is guaranteed to continue execution after the exact amount of time defined in the sleep (long)parameter.
D. A thread can continue execution before the amount of time defined in the sleep (long) parameter.
E. A thread can continue execution after the amount of time defined in the sleep (long) parameter
F. Only runtime exceptions are thrown by the sleep method.
G. A thread loses all object monitors (lock flags) when calling the sleep method.
Answer: A,C,E
Explanation:
sleep (long millis) not B Causes the currently executing thread to sleep (temporarily cease execution) for the specified number ofmilliseconds(A, not B) millis - the length of time to sleep in milliseconds. throws InterruptedException: - if another thread has interrupted the current thread. The interrupted status ofthe current thread is cleared when this exception is thrown. java.lang.Throwable java.lang.Exception java.lang.InterruptedException The thread does not lose ownership of any monitors. It means that if the thread has an object-monitor, all otherthreads that need that monitor are blocked. This method can be called regardless whether the thread has any monitor or not.