SCJP 5.0 Questions
01. MockExam - 01
02. MockExam - 02
03. MockExam - 03
04. AutoBoxing - 1 (10 questions)
05. AutoBoxing - 2 (10 questions)
06. Generics 1 - 6 Questions
07. Generics 2 - 7 Questions
08. Generics 3 - 10 Questions
09. Generics 4 - 10 Questions
10. Generics 5 - 10 Questions
11. Generics 6 - 10 Questions
12. Enum 1 - 10 Questions
13. Enums 2 - 10 Questions
14. Enums 3 - 15 Questions
15. Var Args 1 - 10 Questions
16. Var Args 2 - 10 Questions
17. SCJP 5.0 Mock Questions -1
18. Declaration,Access Control-1
19.Java File IO Package - 1
20.Java File IO Package - 2
21.Language Features - 1
22.New Api's - 1 (10 questions)
23.New Api's - 2 (12 questions)
24.Objective - 1 (20 questions)
25.Objective - 2 (10 questions)
26.Objective - 3 (10 questions)
27.Objective - 4 (10 questions)
28.Objective - 5 (10 questions)
29.Objective - 6 (10 questions)
30.Objective - 7 (10 questions)
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

Answers to SCJP 5.0 - 1

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

javabeat | advertise | about us | contact | useful resources
Copyright (2004 - 2013), JavaBeat