Question

in JAVA24. Suppose that a class has an overloaded method named add with the following two implementations: double add (int x, double29. Here is the code for a recursive method named mystery. What is printed when mystery(1, 2) is called? How many recursive c

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

24)

add is an example of method overloading.

So,

a)

It will return 6.14

b)

It will return 7.14

c)

It will give error since there are2 methods satisfying

d)

It will also give error since there is no method with 2 doubles as parameters

Note: Brother According to HomeworkLib's policy we are only allowed to answer first Q if there are many. So, I request you to post other part as separate posts

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
in JAVA 24. Suppose that a class has an overloaded method named add with the following...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the following method: public static int mystery (int x, double y, char ch) {              ...

    Consider the following method: public static int mystery (int x, double y, char ch) {               int u; if ('A' <= ch && ch <= 'R')                   return (2 * x + (int)(y)); else return((int)(2 * y) - x); } What is the output of the following Java statements? a. System.out.println (mystery(5, 4.3, 'B')); b. System.out.println (mystery(4, 9.7, 'v')); c. System.out.println (2 * mystery(6, 3.9, 'D'));

  • PROBLEM: Write a recursive method named Division that takes two integers X and Y returns the...

    PROBLEM: Write a recursive method named Division that takes two integers X and Y returns the result of integer division (i.e., 8 / 3 = 2). Please comment on every line of code. EXISITNG CODE: int Exponentiation(int X, int Y) { if (Y == 0) // base case return 1; else // recursive case return X * Exponentiation(X, Y - 1); //make recursive call } int Multiply(int X, int Y){ if(Y == 0){ return 0; } else{ return X +...

  • JAVA question For the following code, remember to make a table to keep track of the...

    JAVA question For the following code, remember to make a table to keep track of the various x y z values. public class Mystery6 { public static void main(String[] args) { int x = 1; int y = 2; int z = 3; z = mystery(y, x, y); // Statement 1 System.out.println(x + " " + y + " " + z); // Statement 2 x = mystery(z, y, x); // Statement 3 System.out.println(x + " " + y +...

  • PROBLEM: Write a recursive method named Addition that takes two integers X and Y returns their...

    PROBLEM: Write a recursive method named Addition that takes two integers X and Y returns their sum. Please comment on every line of code. EXISTING CODE: int AddToN(int n) { if (n == 0) { // base case return 0; } else { // recursive case return n + AddToN(n-1); //make recursive call } } void printStars (int n) { if (n==0 ) { //base case cout <<""; } else{ printStars(n-1); cout << ""; } } } int sumRange (...

  • JAVA language Add a recursive method to the program shown in the previous section that states...

    JAVA language Add a recursive method to the program shown in the previous section that states how many times a particular value appears on the stack. Code: class Stack { protected Node top; Stack() { top = null; } boolean isEmpty() { return( top == null); } void push(int v) { Node tempPointer; tempPointer = new Node(v); tempPointer.nextNode = top; top = tempPointer; } int pop() { int tempValue; tempValue = top.value; top = top.nextNode; return tempValue; } void printStack()...

  • Create a class named Billing that includes three overloaded computeBill() methods for a photo book store....

    Create a class named Billing that includes three overloaded computeBill() methods for a photo book store. • When computeBill() receives a single parameter, it represents the price of one photo book ordered. Add 8% tax, and return the total due. • When computeBill() receives two parameters, they represent the price of a photo book and the quantity ordered. Multiply the two values, add 8% tax, and return the total due. • When computeBill() receives three parameters, they represent the price...

  • Write a full program that will accept exactly  three command line arguments that can be interpreted as...

    Write a full program that will accept exactly  three command line arguments that can be interpreted as integers, and will add them up. If there aren't exactly 3 command line arguments, print an error message and terminate the program. Suppose your program is called Add.java. Then running the command java Add 1 2 3 will output 6, and running java Add, for example, will cause the program to shut down. Consider the following recursive method: public static int mystery (int n)...

  • PROBLEM: Write a recursive method named SumEvens that takes an integer X and returns the sum...

    PROBLEM: Write a recursive method named SumEvens that takes an integer X and returns the sum of even digits in X. Please comment on every line of code. EXISTING CODE: int numTwos(int n) { int right = n % 10; int remain = n / 10; if(n==0) { return 0 ; } else if(right ==2) { //rightmost digit is 2 return 1 + numTwos(remain); else { return 0 + numTwos(remain); } } int SumDigits(int X) { if (X == 0)...

  • 3) Consider the following recursive method, what will be the output for the following method calls?...

    3) Consider the following recursive method, what will be the output for the following method calls? Explain. (25 pts.) public static void sample (int number) if (number < 0) { System.out.println( superwriteVertical (-number); System.out.println(number); superwriteVertical (number/ 10); else if (number 10) else ( System.out.print1n(number % 18); sample(-100); sample(50); sample(1024);

  • 1. Write a new class, Cat, derived from PetRecord – Add an additional attribute to store...

    1. Write a new class, Cat, derived from PetRecord – Add an additional attribute to store the number of lives remaining: numLives – Write a constructor that initializes numLives to 9 and initializes name, age, & weight based on formal parameter values 2. Write a main method to test your Cat constructor & call the inherited writeOutput() method 3. Write a new writeOutput method in Cat that uses “super” to print the Cat’s name, age, weight & numLives – Does...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT