Question

Identify and explain which type of polymorphism technique is used in the following code A- class...

Identify and explain which type of polymorphism technique is used in the
following code
A-
class Calculator {
public void add(int i, int j) {
System.out.println("Integer addition");
}
public void add(int i, double j) {
System.out.println("Integer and double addition");
}
public void add(double i, double j) {
System.out.println("Double addition");
}
}
B-
public class MyClass {
void test(int a) {
System.out.println("a: " + a);
}
void test(int a, int b) {
System.out.println("a and b: " + a + "," + b);
}
double test(double a) {
System.out.println("double a: " + a);
return a * a;
}
}

Homework Answers

Answer #1

Answer : Compile time Polymorphism

Explanation :

Compile time polymorphism is also known as method overloading, in method overloading, one method can repeated many times as it wants with the different number of argument, different types of the datatype, and different return types, which is said to be as the compile time polymorphism

In Calculator class :

public void add(int i, int j)

public void add(int i, double j)

public void add(double i, double j)

These 3 methods hae the same names, but if you can see the datatypes in the parameters are different one is int and other one is double

In MyClass class :

void test(int a)

void test(int a, int b)

double test(double a)

you can see these 3 methods have the same name, but different return types and different number of arguments and different type of data types used in the parameters

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
For the following piece of Java code: a) State which object creation mechanism is being used...
For the following piece of Java code: a) State which object creation mechanism is being used b) Explain how you determined which object creation mechanism is being used c) Complete the missing portions of the code (indicated by underscores) ____________________ part1 { public void function1(String someInput); public double function2(); public int function3(int thisVal, int thatVal); } public ____________________part2 ____________________ { double aNumber; public void function1(String someInput) { System.out.println(someInput); } public double function2() { aNumber = 6.0; return aNumber; } public...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class Food {     static int count;     private String flavor = "sweet";     Food() { count++; }     void setFlavor(String s) { flavor = s; }     String getFlavor() { return flavor; }     static public void main(String[] args) {         Food pepper = new Food();         System.out.println(pepper.getFlavor());     } } a. a class variable b. a constructor c. a local object variable d....
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*;...
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*; import javax.swing.*; public class Clicker extends JFrame implements ActionListener {     int count;     JButton button;     Clicker() {         super("Click Me");         button = new JButton(String.valueOf(count));         add(button);         button.addActionListener(this);         setSize(200,100);         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         setVisible(true);     }     public void actionPerformed(ActionEvent e) {         count++;         button.setText(String.valueOf(count));     }     public static void main(String[] args) { new Clicker(); } } a. add(button);...
In this code, I build a single-linked list using a node class that has been created....
In this code, I build a single-linked list using a node class that has been created. How could I change this code to take data of type T, rather than int. (PS: ignore the fact that IOHelper.getInt won't work for the type T... ie second half of main). Here's my code right now: public class SLList { public SLNode head = null; public SLNode tail = null; public void add(int a) {// add() method present for testing purposes SLNode newNode...
I wrote the following java code with the eclipse ide, which is supposed to report the...
I wrote the following java code with the eclipse ide, which is supposed to report the number of guesses it took to guess the right number between one and five. Can some repost the corrected code where the variable "guess" is incremented such that the correct number of guesses is displayed? please test run the code, not just look at it in case there are other bugs that exist. import java.util.*; public class GuessingGame {    public static final int...
Mention the concepts analyzed from the below given program and write the output. [0.5 M] class...
Mention the concepts analyzed from the below given program and write the output. [0.5 M] class Test { int a, b; Test(int i, int j) { a = i; b = j; } void meth(Test s) { s.a *= 2; s.b /= 2; } } class demo { public static void main(String args[]) { Test ob = new Test(15, 20); System.out.println("Before call: " + ob.a + " " + ob.b); ob.meth(ob); System.out.println("After call: " + ob.a + " " +...
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields,...
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields, as well as the methods for the Inventory class (object). Be sure your Inventory class defines the private data fields, at least one constructor, accessor and mutator methods, method overloading (to handle the data coming into the Inventory class as either a String and/or int/float), as well as all of the methods (methods to calculate) to manipulate the Inventory class (object). The data fields...
Provide A UML for the Following CODE public class Employee{ public String strName, strSalary; public Employee(){...
Provide A UML for the Following CODE public class Employee{ public String strName, strSalary; public Employee(){    strName = " ";    strSalary = "$0";    } public Employee(String Name, String Salary){    strName = Name;    strSalary = Salary;    } public void setName(String Name){    strName = Name;    } public void setSalary(String Salary){    strSalary = Salary;    } public String getName(){    return strName;    } public String getSalary(){    return strSalary;    } public String...
[Java] I'm not sure how to implement the code. Please check my code at the bottom....
[Java] I'm not sure how to implement the code. Please check my code at the bottom. In this problem you will write several static methods to work with arrays and ArrayLists. Remember that a static method does not work on the instance variables of the class. All the data needed is provided in the parameters. Call the class Util. Notice how the methods are invoked in UtilTester. public static int min(int[] array) gets the minimum value in the array public...
The following program creates a linked list which contains 5 links. Add a method called doubleValue()...
The following program creates a linked list which contains 5 links. Add a method called doubleValue() to the LinkedList class. The doubleValue() method must double the value of the number data field in each link. Add the required code to the main() method to call the doubleValue() method and display the revised list. public class Link { private int number; private Link next;      public Link(int x) { number = x; }    public void displayLink() { System.out.println("The number is:...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • Statistics Discussion: The accuracy of a forecasting technique is evaluated especially using the MSE (mean squared...
    asked 23 minutes ago
  • If the U.S. government manages to close a recessionary gap and achieve potential GDP with fiscal...
    asked 28 minutes ago
  • A block with mass 10kg is on a ramp angled at 20 degrees above the horizontal,...
    asked 28 minutes ago
  • I have a sample of 31 7thgrade girls who took an IQ test.  I calculated the sample...
    asked 35 minutes ago
  • A researcher wishes to estimate the proportion of adults who have​ high-speed Internet access. What size...
    asked 35 minutes ago
  • Brick column in the external corridor of a house, with section size of 440 mm X520...
    asked 36 minutes ago
  • 17.                             Mel has a(n) __________ lien on Ellen’s car after he replaced her clutch. The lien.
    asked 43 minutes ago
  • Jackson Company engaged in the following investment transactions during the current year. Feb 17,Purchased  430 shares of...
    asked 54 minutes ago
  • When might discrimination in the workplace be justified? Might discrimination on the basis of gender or...
    asked 1 hour ago
  • The strength grade of materials used for brick masonry at a certain site is as follows:...
    asked 1 hour ago
  • Show (prove), from the original definition of the integers, that subtraction of integers is well defined....
    asked 1 hour ago
  • How is polarity of a "bond" different than polarity of a "molecule?" What makes a particular...
    asked 1 hour ago