What is the output of the following code? 1: class Mammal { 2: public Mammal(int age) { 3: System.out.print("Mammal"); 4: } 5: } 6: public class Platypus extends Mammal { 7: public Platypus() {8: System.out.print("Platypus"); 9: } 10: public static void main(String[] args) { 11: new Mammal(5); 12: } 13: } *1 pointA. PlatypusB. MammalC. PlatypusMammalD. MammalPlatypusE. The code will not compile because of line 8.F. The code will not compile because of line 11
Question
What is the output of the following code? 1: class Mammal { 2: public Mammal(int age) { 3: System.out.print("Mammal"); 4: } 5: } 6: public class Platypus extends Mammal { 7: public Platypus() {8: System.out.print("Platypus"); 9: } 10: public static void main(String[] args) { 11: new Mammal(5); 12: } 13: } *1 pointA. PlatypusB. MammalC. PlatypusMammalD. MammalPlatypusE. The code will not compile because of line 8.F. The code will not compile because of line 11
Solution
The output of the code will be "Mammal". When the Mammal object is created in the main method, it calls the Mammal constructor which prints out "Mammal". The Platypus class is not used in this code, so "Platypus" is not printed. Therefore, the correct answer is B. Mammal.
Similar Questions
What is the output of the following code? 1: abstract class Reptile { 2: public final void layEggs() { System.out.println("Reptile laying eggs"); } 3: public static void main(String[] args) { 4: Reptile reptile = new Lizard(); 5: reptile.layEggs(); 6: } 7: } 8: public class Lizard extends Reptile { 9: public void layEggs() { System.out.println("Lizard laying eggs"); } 10: } *1 pointA. Reptile laying eggsB. Lizard laying eggsC. The code will not compile because of line 4.D. The code will not compile because of line 5.E. The code will not compile because of line 9.
What is the output of the following code? 1: public abstract class Whale { 2: public abstract void dive() {}; 3: public static void main(String[] args) { 4: Whale whale = new Orca(); 5: whale.dive(); 6: } 7: } 8: class Orca extends Whale { 9: public void dive(int depth) { System.out.println("Orca diving"); } 10: }*1 pointA. Orca divingB. The code will not compile because of line 2.C. The code will not compile because of line 8.D. The code will not compile because of line 9.E. The output cannot be determined from the code provided.
What is the result of the following code? 1: public abstract class Bird { 2: private void fly() { System.out.println("Bird is flying"); } 3: public static void main(String[] args) { 4: Bird bird = new Pelican(); 5: bird.fly(); 6: } 7: } 8: class Pelican extends Bird { 9: protected void fly() { System.out.println("Pelican is flying"); } 10: } *1 pointA. Bird is flyingB. Pelican is flyingC. The code will not compile because of line 4.D. The code will not compile because of line 5.E. The code will not compile because of line 9.
What is the output of the following code? 1: class Arthropod 2: public void printName(double input) { System.out.print("Arthropod"); } 3: } 4: public class Spider extends Arthropod { 5: public void printName(int input) { System.out.print("Spider"); } 6: public static void main(String[] args) { 7: Spider spider = new Spider(); 8: spider.printName(4); 9: spider.printName(9.0); 10: } 11: }
Given1. class Pro{2. 3. public static void main(String args[]){4. System.out.print(new A(5).y);5. System.out.print(new A().x);6. } 7. } 8. 9. class A{10. A(int i){11. y = i;12. System.out.print("A");13. super();14. }15. int y;16. int x = 10;17. } 18. Which is the output?*A510Compilation fails due to multiple errors.Compilation fails due to an error on line 5.A5 followed by an exception.Compilation fails due to an error on line 13.
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.