Professional Documents
Culture Documents
class A {
public static void main(String[] args) {
char a = 'a', b = 'b'; // 'a' = 97, 'b' = 98
System.out.print(a + b + "" + a + b);
}}
Question 2
interface I1 {} interface I2 {}
class Base implements I1 {}
class Sub extends Base implements I2 {}
class Red {
public static void main(String args[]) {
Sub s1 = new Sub();
I2 i2 = s1; // 1
I1 i1 = s1; // 2
Base base = s1; // 3
Sub s2 = (Sub)base; // 4
}}
a. 1
b. 2
c. 3
d. 4
e. None of the above
Question 3
interface I1 {} interface I2 {}
class Base implements I1 {}
class Sub extends Base implements I2 {}
class Orange {
public static void main(String args[]) {
Base base = new Base();
I1 i1 = base; // 1
Sub sub = (Sub)base; // 2
}}
Question 4
interface I1 {} interface I2 {}
class Base implements I1 {}
class Sub extends Base implements I2 {}
class Yellow {
public static void main(String args[]) {
Base base = new Sub(); // 1
I1 i1 = base; // 2
Sub sub = (Sub)base; // 3
I2 i2 = (Sub)base; // 4
}}
a. 1
b. 2
c. 3
d. 4
e. None of the above
Question 5
interface I1 {} interface I2 {}
class Base implements I1 {}
class Sub extends Base implements I2 {}
class Gray {
public static void main(String []args) {
Base[] base = {new Base()}; // 1
Sub sub[] = {new Sub()}; // 2
Object obj = sub; // 3
base = obj; // 4
}}
A compile-time error is generated at which line?
a. 1
b. 2
c. 3
d. 4
e. None of the above
Question 6
interface I1 {} interface I2 {}
class Base implements I1 {}
class Sub extends Base implements I2 {}
class Silver {
public static void main(String []args) {
Base[] base = {new Base()};
Sub sub[] = new Sub[1]; // 1
Object obj = base; // 2
sub = (Sub[])obj; // 3
I1 []i1 = (I1[])obj; // 4
}}