You are on page 1of 4

File Name: A.

java
public class A {
public void xyz() {
}
}

File Name: B.java


public class B extends A {
public void xyz() {
}
}

File Name: MyClass.java


public class MyClass {
public static void main(String args[]) {
A a = new B();
a.xyz();
}
}
What will happen when this program is compiled and executed?
Less
Options
A. A's xyz method will be called
INCORRECTLY ATTEMPTED

B. B's xyz method will be called


CORRECT ANSWER

C. The program will give a compilation error


D. The program will give a run time error

File Name: A.java


public class A {
public void xyz() {
}
}
File Name: B.java
public class B extends A {
public void xyz() {
File Name: MyClass.java
public class MyClass {
public static void main(String args[]) {
B b = new A();
b.xyz();
}
}
What will happen when this program is compiled and executed?
Less
Options
A. A's xyz method will be called
B. B's xyz method will be called
INCORRECTLY ATTEMPTED

C. The program will give a compilation error


CORRECT ANSWER

D. The program will give a run time error

File Name: MyClass.java


public class MyClass {
public static void main(String args[]) {
xyz('1');
}

public static void xyz(int i){


}

public static int xyz(int i){


}

public static void xyz(char c){


}
}
What will happen when this program is compiled and executed?
Less
Options
A. The following method will be called: void xyz(int i)
INCORRECTLY ATTEMPTED

B. The following method will be called: int xyz(int i)


C. The following method will be called: void xyz(char c)
D. The program will give a compilation error
CORRECT ANSWER

File Name: A.java


public class A {
public A() {
}

public void xyz() {


}
}

File Name: B.java


public class B extends A {
public B() {
}

public void xyz() {


}
}

File Name: MyClass.java


public class MyClass {
public static void main(String args[]) {
B b = new B();
b.xyz();
}
}
What will happen when this program is compiled and executed?
Less
Options
A. The calls will be made in the following order: A's constructor, B's constructor, B's xyz method
CORRECT ANSWER

B. The calls will be made in the following order: A's constructor, B's constructor, A's xyz method,
B's xyz method
C. The calls will be made in the following order: B's constructor, A's constructor, B's xyz method
INCORRECTLY ATTEMPTED
D. The program will give a run time error

You might also like