Make your own free website on Tripod.com
1-

class Outer {
	Inner.Inner1 in1 = new Inner.Inner1(); //Line 1
		private class Inner {
			static class Inner1 {
				Inner1(){	//Line 2
					System.out.println("Inner1 constructor");
		
				}
			}
		}

public static void main(String[] args) {
	new Outer();
}
}
A: If Line 1 is substituted with :
Inner.Inner1 in1 = new Inner().new Inner1();
then code compiles fine
B: Line 2 fails to compile because, static inner classes can't have constructor
C: Inner class can't be private 
D: Compiler error

2- 


class Outer {
	static class Inner1 {
		Inner1() {
			System.out.println("Inner1");
		}
		class Inner2 {
			Inner2() {
				System.out.println("Inner2");
			}
		}				
	} 
	
}

public class DemoInner {
	
	public static void main(String[] args) {
		Outer.Inner1 in1 = new Outer.Inner1(); // Line 1
		Outer.Inner1.Inner2 in2 = new Outer.Inner1.Inner2(); // Line 2
	}
}

A: Compile error at line 1 
B: Compile error at line 2 
C: Both lines cause compiler error
D: No compiler error, code is ok and runs fine
E: if Line 2 is substituted with following, code compiles:
	Outer.Inner1.Inner2 in2 = new Outer().Inner1.new Inner2();
F: if Line 2 is substituted with following, code compiles:
	Outer.Inner1.Inner2 in2 = new Outer.Inner1().new Inner2();

3- 

import java.util.*;

class Person {
	String name;
	Person(String name) {
		this.name =name;
	}
}

public class DemoInner {

	public static void main(String[] args) {
		new Comparator<Person>() { 
			public int compare(Person p1, Person p2) {
				return p1.name.compareTo(p2.name);
			}
		}
	}
}
A: Fails to compile due to syntanx error
B: Compiler error due to failing the contract of interface implementation.
C: Compiles fine 
D: None of the above

4- 

public class DemoMethoLocal {
	
	public static void main(String[] args) {
		final int a;	// Line 1
		final int b;	// Line 2
		b=10;		// Line 3
		class MethodLocalClass {
			a=19;  //Line 4		
		}
		
	}
}
(Choose all that apply)
A: Compilation error at Line 1, final a must be initialized when declared
B: Compilation error at Line 2, final b must be initialized when declared
C: Compilation error at Line 3, can't assign a value to final variable
D: Compilation error at Line 4, can't assign a value to final variable