Consider the following pseudo Java code. Which of these options is valid in Java
ID: 3840087 • Letter: C
Question
Consider the following pseudo Java code. Which of these options is valid in Java?
public class AmphibiousVehicle {
public boolean moveForwardAndDock(int x) { . . . }
public int moveForwardAndDock(int x) { . . . }
}
public class AmphibiousVehicle {
public boolean moveForwardAndDock(int x) { . . . }
public int moveForwardAndDock(float x) { . . . }
}
public class AmphibiousVehicle {
public boolean moveForwardAndDock(int x) { . . . }
public boolean moveForwardAndDock(float x) { . . . }
}
Options (a) and (b)
Options (a) and (c)
Options (b) and (c)
Options (a), (b), and (c)
a.public class AmphibiousVehicle {
public boolean moveForwardAndDock(int x) { . . . }
public int moveForwardAndDock(int x) { . . . }
}
public class AmphibiousVehicle {
public boolean moveForwardAndDock(int x) { . . . }
public int moveForwardAndDock(float x) { . . . }
}
public class AmphibiousVehicle {
public boolean moveForwardAndDock(int x) { . . . }
public boolean moveForwardAndDock(float x) { . . . }
}
Options (a) and (b)
e.Options (a) and (c)
f.Options (b) and (c)
g.Options (a), (b), and (c)
Explanation / Answer
f) Options (b) and (c)
This question provides the concept of polymorphism and method overloading. In Java a function with same name but different function signature can be there.This is called polymorphism. In part a) same name and same function signature i.e.int x is there, So it will throw compilation error stating methods with same name. For others function signatures are different, so methods can be overloaded..