Make your own free website on Tripod.com
1-

package bindaas1;

public class Animal {
	public void hide("Animals don't hide anything") {
		
	}
}

package bindaas2;
import bindaas.Animal.*;

class Dog extends Animal {
	
	void callHide() {
		hide();
	}
	public static void main(String... args) {
		new Dog().callHide();	// Line 1
	} 
}
(Choose all that apply)
A: Compiles fine and prints "Animals don't hide anything"
B: Class Animal compiles but class Dog gives Runtime exception
C: Only Line 1 of the Dog class causes compilation problem
D: If we substitute the Line 1 with following line the code compiles and runs fine
	hide();
D: Animal is not visible to Dog because it is public is package bindaas1
E: Errors at multiple lines of the class Dog, so compilation fails


2-

package bindaas1;

public class Animal {
	
	protected void eat() {
		System.out.println("Animals prefer idali vada");
	}
}

package bindaas2;
import bindaas1.Animal;

class Dog extends Animal {
	void accessEat() {
		Animal animal = new Animal();	// Line 1
		animal.eat();			// Line 2
	}
	
}


public class Beagal extends Dog{

	public static void main(String ... args) {
		accessEat();		// Line 3
	}	
}

(Choose all that apply)
A: Compilation error due to Line 1 
B: Compilation error due to Line 2
C: Compilation error due to Line 3
D: Code compiles fine and prints "Animals prefer idali vada"
E: Code compiles fine but runtime exception, can't access protected member of Animal class

3-

package bindaas1;

public class Animal {
	
	protected void eat() {
		System.out.println("Animals prefer idali vada");
	}
}

package bindaas2;
import bindaas1.Animal;

class Dog extends Animal {
	void accessEat() {
		Dog dog = new Dog();	// Line 1
		dog.eat();		// Line 2
	}
	
}


public class Beagal extends Dog{

	public static void main(String ... args) {
		Dog d1 = new Dog();
		d1.eat();		// Line 3
		accessEat();		// Line 4
	}	
}
(Choose all that apply)
A: Compilation error due to Line 1 
B: Compilation error due to Line 2
C: Compilation error due to Line 3
D: Compilation error due to Line 4
E: Code compiles fine and prints 
"Animals prefer idali vada" 
"Animals prefer idali vada"

4-

package bindaas1;

public class Animal {
	
	protected void eat() {
		System.out.println("Animals prefer idali vada");
	}
}

package bindaas2;
import bindaas1.Animal;

class Dog extends Animal {
	
}


public class Beagal extends Dog{

	public static void main(String ... args) {
		Dog d1 = new Beagal(); // Line 1
		d1.eat();	// Line 2
	}	
}
(Choose all that apply)
A: Compilation error due to Line 1, Beagal can't be casted to Dog 
B: If Line 1 is substituted by: 
Dog d1 = (Dog) new Beagal();
Code compiles fine and runs well

C: Compilation error due to Line 2

D: If we replace Line 2 by:
((Dog)d1).eat();
Code compiles and runs fine

E: If we replace Line 2 by ((Animal)d1).eat();
Code compiles and runs fine

F: If we replace Line 2 by ((Beagal)d1)).eat();
Code compiles and runs fine

G: No problem in code, it compiles fine and prints 
"Animals prefer idali vada"

5- 

package bindaas1;

public class Animal {
	protected void display() {
		System.out.println("Animals look tension free always");
	}
}

package bindaas2;

import bindaas1.Animal;

class Dog extends Animal {

}

public class Pooh {
	public static void main(String... args) { 
		Dog d1 = new Dog(); // Line 1
		d1.display();	// Line 2
	}
} 
(Choose all that apply)
A: Prints "Animals look tension free always.
B: Compiler error due to Line 1
C: Compiler error due to Line 2
D: Compiles bu run time exception, do display method found
E: Animal class is invisible to the world because it is public, so compiler error :)


6-

package bindaas1;

public class Animal {
	static void display() {
		System.out.println("I am visible to everybody");
	}
}

1: package bindaas2;
2: import bindaas1;
3: import iava.bindaas1;
4:
5:class Dog extends Animal {
5:	public static void main(String[] args) {
6:		display();		
7:	
8:}
9:}
(Choose all that apply)

A: Prints "I am visible to everybody"
B: Remove Line 1, code compiles and runs
C: Remove Line 2, code compiles and runs
D: Remove Line 3, code compiles and runs
E: Remove Line 6, code compiles and runs
F: None of the above

7-

package bindaas1;
public class Animal {
	protected static int a=555;
}

package bindaas2;
import bindaas1.Animal;

class Dog extends Animal{
	public static void main(String... args) {
		System.out.println("a = " + a);		// Line 1
		Animal a1 = new Animal();		// Line 2
		System.out.println("a1.a " + a1.a);	// Line 3
	}
}
(Choose all that apply)
A: Compilation fails due to Line 1
B: Compilation fails due to Line 2
C: Compilation fails due to Line 3
D: If we remove Line 1 code compiles and runs
E: If we remove Line 2 and 3 code compiles and runs
F: Prints :
a = 555
a1.a = 555


8-
package bindaas1;

public class Animal {
	private final void display() {
		System.out.println("Animals can's speak like human!");
	}	
}

package bindaas2;
import bindass1.Animal;
class Dog extends Animal {
	public void display() {
		System.out.println("Dog can speak but human can't understand the wordings");
	}

	public static void main(String... args) {
		Animal animal = new Dog();
		animal.display();
	}	
} 

A: final method of the Animal class can't be overridden, therefore compilation error in Dog class
B: Class Animal must be marked final because it is required to compile the Animal class
C: Prints:
Animals can's speak like human!
D: Prints:
Dog can speak but human can't understand the wordings
E: None of the above

9-

package bindaas1;

public class Animal {
	private final void display() {
		System.out.println("Animals can's speak like human!");
	}	
}

package bindaas2;
import bindass1.Animal;
class Dog extends Animal {
	public void display() {
		System.out.println("Dog can speak but human can't understand the wordings");
	}

	public static void main(String... args) {
		Dog dog = new Dog();
		dog.display();
	}	
} 

A: final method of the Animal class can't be overridden, therefore compilation error in Dog class
B: Class Animal must be marked final because it is required to compile the Animal class
C: Prints:
Animals can's speak like human!
D: Prints:
Dog can speak but human can't understand the wordings
E: None of the above

10-

package bindaas1;

public class Animal {
	protected static void play() {
		System.out.println("Playing Animal!");
	}	
}

package bindaas2;
import bindass1.Animal;
class Dog extends Animal {
	public void static play() {
		System.out.println("Playing Dog!");
	}

	public static void main(String... args) {
		Animal animal = new Dog();
		animal.display();
		Dog dog = new Dog();
		dog.display();
	}	
} 

A: static method play() can't be overridden by Dog, so compiler error in Dog

B: protected member can't be static so both compilations fail.

C: Prints:
Playing Animal 
Playing Animal

D: Prints:
Playing Animal 
Playing Dog

E: Prints:
Playing Dog
Playing Dog

F: None of the above