About  | Contact  | Site Map  |  Mirror   
Voodoo Exam  |  Question Bank  |  Databases  |  Tutorials   

In this Section
Question Bank 1
Question Bank 2
Question Bank 3
Objective 2



Previous Section
Back to Java
Voodoo Exam
Question Banks
Tutorials
Applets


Main Links
Home
Java
Tabs
Downloads
About Myself


   

Question Bank 3

We have moved to a new website(www.irixtech.com) where you can now take mock exams online, come back & review your answers later, ask questions in our forums & SCJP questions ranging from SCJP 1.4 to SCJP 6.0, including these question banks & dumps from this site.

Click here to be taken to our new website.


Comments & suggestions will be highly appreciated . If you'd like to see your question's here mail me .


1. Will the following code compile ? If yes choose the most correct two options .

class Q011{
	public static void main(String args[]){
		char a = 'a' + 2;
		System.out.println(a);
		int i = 2;
		char c = 'a' + i;//---1
		System.out.println(c);//---2
		
	}
};

Options :

  1. Compile-time error " Explicit cast needed to convert int to char "
  2. The code can be made to compile by commenting out lines marked as 1 & 2
  3. The code can be made to compile by commenting out the line " char a = 'a' + 2; "
  4. The output is
    67
    67

2. What is the output ? FYI ( int ) ' A ' = 65 

class Q1{
	public static void main(String args[]){
		byte b = 65;
		switch (b)
		{
		case 'A':
			System.out.println("A");
			break;
		case 65:
			System.out.println("65");
			break;
		default:
			System.out.println("default");
		
		}
	}
};

Options :

  1. A
  2. 65
  3. Compile time error , case 65 : duplicate case label
  4. Runtime error "Duplicate case label: 65"
  5. default

3. Will the output from the following two code snippets be any different ?

Snippet 1 :
		for ( int i = 0 ; i < 5 ; i++ )
		{
			System.out.println(i);
		}

Snippet 2 :
		for ( int i = 0 ; i < 5 ; ++i )
		{
			System.out.println(i);
		}

Options :

  1. yes
  2. no

4. What is the output of the following code ? FYI 1 divided by 2 = 0.5

class Q009{
	public static void main(String args[]){
		float f = 1/2;
		System.out.println(f);
	}
};

Options :

  1. Compile-time error float f = 1 / 2 : explicit cast needed to convert int to float
  2. 0.0
  3. 0.5
  4. ClassCastException thrown at run-time

5. What is the output for the following code ?

class Torment{

	int i = 2;

	public static void main(String args[]){
		int i = 12;
		System.out.println(i);
	}
};

Options :

  1. Compiler error , System.out.println ( i ) : can't make a static reference to a non static variable i
  2. Output = 2
  3. Output = 12
  4. Compiler error , i = 12 : variable i is already defined in this class

6. What is the output ?

class FearFactory{
	static{
		System.out.println("Genesis");
	}

	FearFactory(){
		System.out.println("Birth");
	}

	public static void main(String args[]){
		//I'm Lazy
	}
};

Options :

  1. Output = Birth
  2. Output = Genesis
  3. No output generated
  4. Compiler error , System.out.println ( " Genesis " ) : type expected

7. Consider the following class . Which of the marked lines need to be commented out for the class to compile correctly ?

class Evolve{

	static int i = 1;
	static int j = 2;
	int x = 3;
	static int y = 6;

	public static void main(String args[]){
		System.out.println(i + j);//---1
		System.out.println(x + i);//---2
		System.out.println(i + y);//---3
		System.out.println(x + j);//---4
	}
};

Options :

  1. 1 & 2
  2. 1 ,2 & 4
  3. 3 & 4
  4. 2 & 4
  5. 1 , 2 & 3

8. What is the compiler error generated ( if any ) by the following piece of code .

class Jelly{

	public static void main(String args[]){
		float f = 1./2;
		System.out.println(f);
	}
};

Options :

  1. float f = 1. / 2 : invalid numeric type
  2. float f = 1. / 2 : explicit cast needed t convert int to float
  3. System.out.println ( f ) : can't invoke a method on primitive data types
  4. No problem , the code compiles fine .
  5. float f = 1. / 2 : explicit cast needed to convert double to float

9. Will the following class compile ? If yes what is the output ?

class Envy{
	static int i;

	Envy(){
		++i;
	}

	public static void main(String args[]){
		System.out.println(i);
	}
};

Options :

  1. Yes , it compiles but NullPointerException thrown at runtime
  2. Compiler error , System.out.println ( i ) : variable i may not have been initialized
  3. Yes it compiles & output = 0
  4. Yes it compiles & the output = 1
  5. Compiler error , ++ i : can't make a nonstatic reference to a static variable , i

10. Choose all the valid declarations for the main method from the list below ( any  three )

	a. public void main(String args[])
	b. public static int main(String args[])
	c. public static void main(String [] ka)
	d. public static void main(String [] args)
	e. public static void main(String ka [])

Answer :

  1. a & b
  2. c
  3. b
  4. b
  5. c
  6. b
  7. d
  8. e
  9. c
  10. c , d & e

End of Page

Disclaimer  |  Contact  |  Mirror  |  Downloads
© 2000-2002 Ashish Hareet