Professional Documents
Culture Documents
1. Expression (s instanceof java.util.Date) will return false if 's' was declared as a variable of class
java.lang.String.
a) True
b) False
2. Consider the following program:
class SuperClass {
SuperClass() {
foo();
}
public void foo(){
System.out.println("In SuperClass.foo()");
}
}
class SubClass extends SuperClass {
public SubClass() {
member = "HI";
}
public void foo() {
System.out.println("In Derived.foo(): " + member.toLowerCase());
}
private String member;
public static void main(String[] args) {
SuperClass reference = new SubClass();
reference.foo();
}
}
3. Consider the following class:
package com.enthu;
public class Resource {
private String data = "DATA";
String getData(){
return data;
}
void setData(String data){
this.data = data == null ? "" : data;
}
boolean equals(Resource r){
return (r != null && r.getData().equals(this.getData()));
}
}
Identify the options that correctly describe the behavior of the above class.
a) If two distinct Resource objects are considered to be equal, then their 'data' fields must have contained the same string value.
b) Option 1 would be correct only if the provided equals(...) method is made public.
c) Two distinct Resource objects may be considered "not equal" even if their data values are same.
d) The class will not compile because equals method is not correctly overridden.
e) The statement : new Resource().equals(new Resource()); will always return true.
f) The statement new Resource().equals(new Object()); will throw a ClassCastException at runtime.
g) The statement new Resource().equals(new Object()); will not compile.
4. Given
Connection con = DriverManager.getConnection(dbURL);
//code for enabling transactions
String updateString =
"update SALES set T_AMOUNT = 100 where T_NAME = 'BOB'";
Which of the following are valid method declarations for a class that says it implements I1 and I2 ?
a) Both, public void m1() throws FileNotFoundException; and public void m1() throws IOException;
b) public void m1() throws FileNotFoundException
c) The class cannot implement both the interfaces as they have conflicting methods.
d) public void m1() throws Exception;
e) None of the above.
7. Consider these two interfaces:
interface I1
{
void m1() throws java.io.IOException;
}
interface I2
{
void m1() throws java.sql.SQLException;
}
What methods have to be implemented by a class that says it implements I1 and I2 ?
a) Both, public void m1() throws SQLException; and public void m1() throws IOException;
b) public void m1() throws Exception
c) The class cannot implement both the interfaces simultaneously as they have conflicting methods.
d) public void m1() throws SQLException, IOException;
e) None of the above.
8. The signature of a method in a class is as follows:
public static <E extends CharSequence> List<? super E> doIt(List<E> nums)
f) None of these