Knowee
Questions
Features
Study Tools

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: }

Question

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: }

🧐 Not the exact question you are looking for?Go ask a question

Solution

The output of the code will be:

SpiderArthropod

Explanation:

In line 7, a new Spider object is created.

In line 8, the printName method of the Spider class is called with an integer argument, which prints "Spider".

In line 9, the printName method of the Arthropod class is called with a double argument, which prints "Arthropod".

Since there are no line breaks or spaces in the print statements, the output is "SpiderArthropod".

This problem has been solved

Similar Questions

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

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 Java code?Code:class HackerEarth{ public void print() { System.out.println("Inside HackerEarth"); }}class Hacker extends HackerEarth{ public void print() { System.out.println("Inside Hacker"); }}public class HackerEarthMain{ public static void main(String[] args) { HackerEarth obj1 = new HackerEarth(); Hacker obj2 = new Hacker(); ((HackerEarth) obj2).print(); obj1 = obj2; obj1.print(); }}

Given:class FourWheeler { public FourWheeler () { System.out.print(1); } } class Car extends FourWheeler{ public Car() { System.out.print(2); } } class Audi extends Car{ public Audi() {System.out.print(3); } } public class Driver{ public static void main( String[] argv ) {new Audi(); } } What is the result when this code is executed?Select one:a.The code runs with no outputb.321c.123d.3

What is the output of the following code? _____public class Test {  public static void main(String[] args) {    new Person().printPerson();    new Student().printPerson();  }}class Student extends Person {  @Override  public String getInfo() {    return "Student";  }}class Person {  public String getInfo() {    return "Person";  }    public void printPerson() {    System.out.println(getInfo());  }}A. Person PersonB. Person StudentC. Stduent StudentD. Student Person

1/3

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.