JavaBeat
SCJP 5.0 Home New to SCJP? Objectives Articles Mock Exams Tutorials Resources SiteMap & Links Forums  

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)
Subscribe to SCJP 5.0 Group

SCJP 5.0 [Declaration and Access Control] - 1

by Viral Gala
17/10/2007

Question 1 : what will be the output?


class Employee
{
  private 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  JavaBeat11
{
	public static void main(String[] args) 
	{
		Employee x1 = new Employee(1,"abc");
		Employee x2 = new Employee(2,"def");
		Employee x3 = new Employee(3,"ghi");
		
		x1.empid=11;

		System.out.println("Employee id of x1 is :  "+ x1.getEmpId());
		System.out.println("Employee id of x2 is :  "+ x2.getEmpId());
		System.out.println("Employee id of x3 is :  "+ x3.getEmpId());


	}
}
1. compile time error.
2. Runtime Error.
3. Employee id of x1 is : 11
Employee id of x2 is : 2
Employee id of x3 is : 3
4. Employee id of x1 is : 1
Employee id of x2 is : 2
Employee id of x3 is : 3

Question 2:which are invalid declaration?

1. final int x2age = 5;
2. static int _name;
3. protected int abc;
4. abstract int emp;

question 3 : which are invalid keyword?

1. native
2. synchronized
3. goto
4. main

Question 4 : which are invalid keyword?

1. throw
2. throws
3. strictfp
4. struct
5. enum

Question 5 : Both the class are in different file.what will be the output?


package EMPone;
 class Employee
{
  public int empid;
  public String name;
  public int age;
  static int count=0;
  public  Employee(int id,String name,int age)
		{
				this.empid=id;
				this.name=name;
				this.age=age;
				count++;
		}

  
}


package EMPtwo;
import EMPone.Employee;
class  JavaBeat15
{   
	public static void main(String[] args) 
	{
		Employee x1 = new Employee(1,"abc",21);
		
		x1.age = 25;

		System.out.println("The age of Employee x1 is "+x1.age);


	}
}
1. compile time error.
2. Runtime Error.
3. The age of Employee x1 is 21
4. The age of Employee x1 is 25

Question 6 : Both the class are in different file.what will be the output?


package EMPone;
public class Employee
{
  public int empid;
  public String name;
  public int age;
  static int count=0;
  public  Employee(int id,String name,int age)
		{
				this.empid=id;
				this.name=name;
				this.age=age;
				count++;
		}

  
}


package EMPtwo;
class  JavaBeat16
{   
	public static void main(String[] args) 
	{
		Employee x1 = new Employee(1,"abc",21);
		
		x1.age = 25;

		System.out.println("The age of Employee x1 is "+x1.age);


	}
}
1. compile time error.
2. Runtime Error.
3. The age of Employee x1 is 21
4. The age of Employee x1 is 25

Question 7 : what will be the output?


class JavaBeat17
{   
    public int x=5;
	public int y=6;
	public static void main(String[] args) 
	{    private int x=5;
		 int i=0;
	     for (i=0;i<5;i++)
		  x++;
		System.out.println("  "+x+i);
	}
}
1. Compile time error
2. 55
3. 105
4. 15

Question 8 : Both the class are in different file. what will be the output?


package EMPone;
public class Employee
{
  public int empid;
  public String name;
  protected  int age;
  
  public  Employee(int id,String name,int age)
		{
				this.empid=id;
				this.name=name;
				this.age=age;
				
		}

  
}


package EMPtwo;
import EMPone.Employee; 
class  JavaBeat18
{   
	public static void main(String[] args) 
	{
		Employee x1 = new Employee(1,"abc",21);
		
		x1.age = 25;

		System.out.println("The age of Employee x1 is "+x1.age);


	}
}
1. compile time error.
2. Runtime Error.
3. The age of Employee x1 is 21
4. The age of Employee x1 is 25

Question 9 : Whether below code will compile or not?


interface Department
{
 int Depid =15;
 int getDepID();
}
class  Manager implements Department
{ 
  String name;
  String Location;

    public int getDepID()
    {
	      return Depid;
	}

	public static void main(String[] args) 
	{   
	    	Manager x = new Manager();
		x.Depid =16;
		System.out.println("The Department is "+x.getDepID());
	}
}
Whether above code will compile or not
1. True
2. False

Question 10 : Both the class are in different file.what will be the output?


package EMPone;
public class Employee
{
  public int empid;
  public String name;
  protected  int age;
  static protected int count=0;
  public  Employee(int id,String name,int age)
		{
				this.empid=id;
				this.name=name;
				this.age=age;
				count++;
		}
 public Employee()
      {}

  
}

package EMPtwo;
import EMPone.Employee; 
class  JavaBeat20 extends Employee
{   
	public static void main(String[] args) 
	{
		Employee x1 = new Employee(1,"abc",21);
		
		x1.count  = 10;

		System.out.println("The count of Employee  is "+x1.count);


	}
}
1. compile time error.
2. The count of Employee is 1
3. The count of Employee is 10
4. The count of Employee is 0

Answers to SCJP 5.0 [Declaration and Access Control] - 1


JavaBeat Website (2004-2008), India
javabeat | about us | useful resources
Copyright (2004 - 2008), JavaBeat