300+ Mock Questions on SCJP 5.0 - JUST Rs.200 or 5 USD
Send us mail to sales@javabeat.net more details
|
|
Order Now
|
|
|
350 Mock Questions on SCJP 1.5 - JUST Rs.250 or 7 USD
Send us mail to sales@javabeat.net
more details
|
|
SCJP 5.0 Mock Exam - 1
by Viral Gala
04/10/2007
Question 1 : which option is true?
class Employee
{
int empid;
String name;
Employee(int id,String name)
{
this.empid=id;
this.name=name;
}
public int getEmpId()
{
return empid;
}
public String getString()
{
return name;
}
boolean equals(Object o)
{
if ((o instanceof Employee) && (((Employee)o).getEmpId()
== this.empid))
{
return true;
}
else
{
return false;
}
}
}
class JavaBeat1
{
public static void main(String[] args)
{
Employee x1 = new Employee(1,"abc");
Employee x2 = new Employee(2,"def");
Employee x3 = new Employee(1,"abc");
if( x1.equals(x3) )
{
System.out.println("x1 and x3 are equal");
}
else
{
System.out.println("x1 and x3 are not equal");
}
}
}
1. compile Time error.
2. Runtime Error.
3. x1 and x3 are equal.
4. x1 and x3 are not equal.
Question 2 : which statement are true?
class Employee
{
int empid;
String name;
Employee(int id,String name)
{
this.empid=id;
this.name=name;
}
public int getEmpId()
{
return empid;
}
public String getString()
{
return name;
}
public boolean equals(Employee o)
{
if ((o instanceof Employee) && (((Employee)o).getEmpId() == this.empid))
{
return true;
}
else
{
return false;
}
}
}
class JavaBeat2
{
public static void main(String[] args)
{
Employee x1 = new Employee(1,"abc");
Employee x2 = new Employee(2,"def");
Employee x3 = new Employee(1,"abc");
if( x1.equals(x3) )
{
System.out.println("x1 and x3 are equal");
}
else
{
System.out.println("x1 and x3 are not equal");
}
}
}
1. compile Time error.
2. Runtime Error.
3. x1 and x3 are equal.
4. x1 and x3 are not equal.
5. equals method in class Employee is legal overridding of equals method in class Object
Question 3 : which variable of class should not be used in hashCode method?
1. private
2. transient
3. final
4. public
class ABC
{
transient int x=9;
int hashCode()
{
return x;
}
}
(for eg consider value of variable x as 9. x is transient
if x is serialized then after deserialization value of x is 0
due to which same object of ABC may get different hashcode value
Question 4 : which option is true?
import java.util.*;
class Employee
{
int empid;
String name;
Employee(int id,String name)
{
this.empid=id;
this.name=name;
}
public int getEmpId()
{
return empid;
}
public String getString()
{
return name;
}
public boolean equals(Object o)
{
if ((o instanceof Employee) && (((Employee)o).getEmpId()
== this.empid))
{
return true;
}
else
{
return false;
}
}
}
class JavaBeat3
{
public static void main(String[] args)
{
Employee x1 = new Employee(1,"abc");
Employee x2 = new Employee(2,"def");
Employee x3 = new Employee(1,"abc");
List y = new ArrayList();
y.add(x1);
y.add(x2);
y.add(x3);
Iterator i3 = y.iterator();
while (i3.hasNext()) {
Employee y2 = i3.next();
System.out.print(y2.getString()+ " ");
}
System.out.print(y.size()+ " ");
}
}
1. compile Time error.
2. Runtime Error.
3. abc def abc 3
4. abc def 2
Question 5 : which option is true?
import java.util.*;
class Employee
{
int empid;
String name;
Employee(int id,String name)
{
this.empid=id;
this.name=name;
}
public int getEmpId()
{
return empid;
}
public String getString()
{
return name;
}
}
class JavaBeat5
{
public static void main(String[] args)
{
Employee x1 = new Employee(11,"abc");
Employee x2 = new Employee(2,"def");
Employee x3 = new Employee(1,"abc");
Set y = new HashSet();
y.add(x1);
y.add(x2);
y.add(x3);
Iterator i3 = y.iterator();
while (i3.hasNext()) {
Employee y2 = (Employee)i3.next();
System.out.print(y2.getString()+ " ");
}
System.out.print(y.size()+ " ");
}
}
1. compile Time error.
2. Runtime Error.
3. abc def abc 3
4. Order of output is not predictable
Question 6 : which option is true?
import java.util.*;
class Employee
{
int empid;
String name;
Employee(int id,String name)
{
this.empid=id;
this.name=name;
}
public int getEmpId()
{
return empid;
}
public String getString()
{
return name;
}
}
class JavaBeat6
{
public static void main(String[] args)
{
Employee x1 = new Employee(1,"abc");
Employee x2 = new Employee(2,"def");
Employee x3 = new Employee(1,"abc");
Map y = new HashMap();
y.put(x1,"comparator");
y.put(x2,"comparable");
y.put(x3,"runnable");
Iterator i3 = y.iterator();
while (i3.hasNext()) {
Employee y2 = (Employee)i3.next();
System.out.print(y2.getString()+ " ");
}
System.out.print(y.size()+ " ");
}
}
1. compile Time error.
2. Runtime Error.
3. abc def abc 3
4. Order of output is not predictable
Question 7 : which option is true?
import java.util.*;
class Employee
{
int empid;
String name;
Employee(int id,String name)
{
this.empid=id;
this.name=name;
}
public int getEmpId()
{
return empid;
}
public String getString()
{
return name;
}
public int hashCode()
{
return empid;
}
public boolean equals(Object o)
{
if ((o instanceof Employee) && (((Employee)o).getEmpId()
== this.empid))
{
return true;
}
else
{
return false;
}
}
}
class JavaBeat7
{
public static void main(String[] args)
{
Employee x1 = new Employee(1,"abc");
Employee x2 = new Employee(2,"def");
Employee x3 = new Employee(1,"ghi");
Map y = new HashMap();
y.put(x1,"comparator");
y.put(x2,"comparable");
y.put(x3,"runnable");
System.out.print(y.size()+ " ");
}
}
1. compile Time error.
2. Runtime Error.
3. 3
4. 2
Question 8 : which option is true?
import java.util.*;
class JavaBeat8
{
public static void main(String[] args)
{
Integer[] x = {1,2,3,4,5};
int[] x1= {1,2,3,4,5};
boolean b;
b=Arrays.equals(x,x1);
if(b)
{
System.out.println("Both arrays are equal");
}
else
{
System.out.println("Both arrays are not equal");
}
}
}
1. compile Time error.
2. Runtime Error.
3. Both arrays are equal
4. Both arrays are not equal
Question 9 : which option will compile?
import java.util.*;
class Employee
{
}
class DeptManager extends Employee
{
}
class ProjManager extends Employee
{
}
1. List<?> x = new ArrayList<Employee>();
2. List<Employee> x1 = new ArrayList();
3. List<Employee> x2 = new ArrayList<DeptManager>();
4. List<? extends Employee> x3 = new ArrayList<DeptManager>;
5. List<? extends ProjManager> x4 = new ArrayList<DeptManager>();
6. List<? super ProjManager> x5 = new ArrayList<Employee>();
Question 10 : which option is true?
import java.util.*;
class Employee
{
public String toString()
{
return("Employee");
}
}
class DeptManager extends Employee
{
public String toString()
{
return("DeptManager");
}
}
class ProjManager extends Employee
{
public String toString()
{
return("ProjManager");
}
}
class JavaBeat10
{
public static void main(String[] args)
{
Employee[] x =new DeptManager[3];
x[0]= new Employee();
x[1]= new DeptManager();
x[2]= new DeptManager();
for(Employee x1 : x)
System.out.println(x1);
}
}
1. compile time error
2. run time error
3. Employee
DeptManager
DeptManager
4. DeptManager
DeptManager
DeptManager
300+ Mock Questions on SCJP 5.0 - JUST Rs.200 or 5 USD
Send us mail to sales@javabeat.net more details
|
|
Order Now
|
|
|
350 Mock Questions on SCJP 1.5 - JUST Rs.250 or 7 USD
Send us mail to sales@javabeat.net
more details
|
|
|