Given: What is the result?
A.
Shining Sun Shining Sun Shining Sun
B.
Shining Sun Twinkling Star Shining Sun
C.
Compilation fails
D.
A ClassCastException is thrown at runtime
Given: What is the result?
A.
Shining Sun Shining Sun Shining Sun
B.
Shining Sun Twinkling Star Shining Sun
C.
Compilation fails
D.
A ClassCastException is thrown at runtime
class Star {
public void doStuff(){
System.out.println(“Twinkling Star”);
}
}
interface Universe{};
class Sun extends Star implements Universe{
public void doStuff(){
System.out.println(“Shining Sun”);
}
}
public class SampleClass {
public static void main(String[] args) {
Sun obj2= new Sun();
Star obj3= obj2;
((Sun)obj3).doStuff();
((Universe)obj2).doStuff();
}
}
===> C
class Star {
public void doStuff(){
System.out.println(“Twinkling Star”);
}
}
interface Universe{
public void doStuff();
};
class Sun extends Star implements Universe{
public void doStuff(){
System.out.println(“Shining Sun”);
}
}
public class SampleClass {
public static void main(String[] args) {
Sun obj2= new Sun();
Star obj3= obj2;
((Sun)obj3).doStuff();
((Star)obj2).doStuff();
((Universe)obj2).doStuff();
}
}
==> A
a