Question
Please choose all the answers that apply. Select 2 options. A class can extend one class and implements many interfaces An interface can extend many
Please choose all the answers that apply. Select 2 options.
A class can extend one class and implements many interfaces | ||
An interface can extend many interfaces | ||
A class can extend one class and many interfaces | ||
A class can implement one class and many interfaces | ||
An interface can extend many classes and interfaces | ||
An interface can implement many classes and interfaces | ||
An interface can implement many interfaces |
4 points
QUESTION 10
Consider the following class: public class A { public int timesTwo(int x) { return x + x; } } Which of the following classes inherits from A but replaces the timesTwo() method with a new implementation?
class B extends A { public int timesTwo (int x) { return x * 2; } } | ||
public class A extends B { public int timesTwo (int x) { return x * 2; } } | ||
public class B extends A { public float timesTwo (float x) { return x * 2.0F; } } | ||
public class B extends A { } |
4 points
QUESTION 11
What is the output of compiling and running the following program? class Category { Category() { System.out.println("Constructor of Category"); } } class SubCategory extends Category { SubCategory() { System.out.println("Constructor of SubCategory"); } } class SubSubCategory extends SubCategory { SubSubCategory() { System.out.println("Constructor of SubSubCategory"); } } public class Tester { public static void main(String[] args) { new SubSubCategory(); } }
None of the mentioned | ||
Constructor of SubSubCategory | ||
Constructor of Category Constructor of SubCategory Constructor of SubSubCategory | ||
Constructor of SubSubCategory Constructor of SubCategory Constructor of Category |
5 points
QUESTION 12
The following program fails to compile, where could possibly be the compilation error(s)? Select 2 options. class Creature { } class Bird extends Creature { } class Falcon extends Bird { } public class Tester { public static void main(String[] args) { Creature c1 = new Creature(); Creature c2 = new Bird(); Bird b1 = (Bird) c1; // Line 1 Bird b2 = (Falcon) c2; // Line 2 Bird b3 = c2; // Line 3 Bird b4 = new Falcon(); // Line 4 Bird b5 = (Bird) new Creature(); // Line 5 Falcon f1 = b4; // Line 6 } }
Line 3 | ||
Line 4 | ||
Line 5 | ||
Line 6 | ||
Line 1 | ||
Line 2 |
4 points
QUESTION 13
What keyword or keywords are used to indicate that a class inherits from another class?
inherits | ||
is a | ||
extends | ||
implements |
4 points
QUESTION 14
Which statement(s), inserted independently at the insertion point in the main function, will compile and run successfully? Select 2 options. class Creature { String getName() { return "Creature"; } } class Bird extends Creature { String getName() { return "Bird"; } } class Falcon extends Bird { String getName() { return "Falcon"; } } public class Tester { public static Bird getIt(Creature c) { System.out.println(c.getName()); return (Bird) c; } public static void main(String[] args) { // insert code here } }
getIt(new Bird()); | ||
getIt(new Falcon()); | ||
getIt(new Creature()); | ||
getIt(new Object()); |
4 points
QUESTION 15
What is the result of compiling and running the following code? class Base { public Base() { System.out.println("Base"); } } public class Derived extends Base { public Derived() { this("JavaChamp"); System.out.println("Derived"); } public Derived(String s) { System.out.println(s); } public static void main(String[] args) { new Derived(); } }
JavaChamp Base Derived | ||
JavaChamp Derived Base | ||
The code will not compile | ||
Base JavaChamp Derived | ||
JavaChamp Derived |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started