Hi! I need help on this JAVA problem. They\'re asking me to write down the outpu
ID: 3769819 • Letter: H
Question
Hi! I need help on this JAVA problem. They're asking me to write down the output of the following problem and to explain why it has this output. They also ask me to establish the difference between overriding and overloading.
The program is:
public class Test1 {
public static void main(String[] args) {
A a = new A();
a.p(10);
a.p(10.0);
}
}
class B {
public void p(double i){
System.out.println(i*2);
}
}
class A extends B{
public void p(int i){
System.out.println(i);
}
}
I would really appreciate the help and rate! Thanks!
Explanation / Answer
Output is
10
20.0
this is so because here the concept of overloading is used. function p() is overloaded by the differene of data type of parameters.
overloading means we can have any number of same function in the class or inherited class, these functions can be executed as and when required. Overriding means we can not execute the previous same copy of the function and the new copy will always be executed.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.