Question

Q15 What is the type of each of the variables? 12 Points Consider the following class: public class Overloaded { public int gQ15.3 2 Points Overloaded o = new Overloaded(); variable = 0.getValue(3. 14); Enter your answer here Q15.4 2 Points Overloade

0 0
Add a comment Improve this question Transcribed image text
Answer #1
public class Main
{
  public int getValue (int i, long l)
  {
    return 42;
  }
  public long getValue (int i)
  {
    return 21;
  }
  public String getValue (double d)
  {
    return "Hello method";
  }
  public char getValue (double d, int i)
  {
    return 'c';
  }
  public static void main (String[]args)
  {
    Main o = new Main ();
    long variable = o.getValue(3);
  }
}

Question 15.1 - o.getvalue(3), this will return an LONG value as the return type of the function is LONG

{ 1 public class Main 2 - { 3 public int getValue (int i, long 1) 4. { 5 return 42; 6 } 7 public long getValue (int i) 8 9 re

Question 15.2 - o.getvalue(3,4), this will return an INT value as the return type of the function is INT

3 4- 5 public int getValue (int i, long 1) { return 42; } { 7 public long getValue (int i) 8 9 return 21; 10 } 11 public Stri

Question 15.3 - o.getvalue(3,14), this will return an STRING value as the return type of the function is STRING

{ 1 public class Main 2-{ 3 public int getValue (int i, long 1) 4. 5 return 42; 6 } 7 public long getValue (int i) 8 { 9 retu

Question 15.4 - o.getvalue(1.0, 3), this will return an CHAR value as the return type of the function is CHAR

1 public class Main 2-{ public int getValue (int i, long 1) { return 42; VO V AWNP } public long getValue (int i) { } return

Question 15.5 - o.getvalue(1.0) + 3, this will return an STRING value as the return type of the function is STRING, the value comes to be double after adding.

{ } { 1 public class Main 2- 3 public int getValue (int i, long 1) 4 5 return 42; 6 7 public long getValue (int i) 8 9 return

Question 15.6 - o.getvalue(3,4) + o.getvalue(1.0, 3), this will return an CHAR value as the return type of the function is CHAR, but this will result in lossy conversion

{ { } { 1 public class Main 2-{ 3 public int getValue (int i, long 1) 4- 5 return 42; 6 } 7 public long getValue (int i) 8 9

Thanks

Add a comment
Know the answer?
Add Answer to:
Q15 What is the type of each of the variables? 12 Points Consider the following class:...
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
  • Question 8 0 Consider the following class definitions, public class Class public String getValue() return "A";...

    Question 8 0 Consider the following class definitions, public class Class public String getValue() return "A"; public void showValue() System.out.print(getValue(); public class Classe extends Class public String getValue() return "B"; The following code segment appears in a class other than ClassA or Classe. ClassA obj = new Class(); obj.showValue(); What, if anything, is printed when the code segment is executed? c) AB ta PendulumPhysical.pdf ^ IN SHM Pendulums ....doc Moh PendulumPhysical.pdf Type here to search o Bi e а в...

  • Q21 Read the following code: 8 Points public class Main { public static int[][] doStuff() {...

    Q21 Read the following code: 8 Points public class Main { public static int[][] doStuff() { int[][] array2D = new int[3][2]; for (int i = 0; i < array2D.length; i++) { for (int j = 0; j < array2D[0].length; j++) { array2D[i][j] = (i+j)%2; } } return array2D; فه public static void main(String[] args) { int[][] a = doStuff(); مہ سره Q21.1 What are the contents of array a? 6 Points Write your answer as if printing the elements row-by-row....

  • We have written the following Node class: class Node { // instance variables private int value;...

    We have written the following Node class: class Node { // instance variables private int value; private Node next; // constructor public Node(int value) { this.value = value; } // get the 'next' variable public Node getNext() { return this.next; } // get the 'value' variable public int getValue() { return this.value; } // set the 'next' variable public void setNext(Node next) { this.next = next; } } TASK: Create a class called List that has the following properties: It...

  • We have written the following Class1 class: class Class1 implements SecretInterface { // instance variable private...

    We have written the following Class1 class: class Class1 implements SecretInterface { // instance variable private int x = 0; // constructor public Class1(int x) { this.x = x; } // instance methods public double myMethod1(double x, double y) { return x - y; } public void myMethod2(int x) { System.out.println(x); } public String myMethod3(String x) { return "hi " + x; } } We have also written the following Class2 class: class Class2 implements SecretInterface { // instance variable...

  • QUESTION 21 What exception will the following program raise? class Main f public static void main(Stringl...

    QUESTION 21 What exception will the following program raise? class Main f public static void main(Stringl args) try System.out.print Hello"1/0); catch ( e) f codes are not provided** DataFormatException InputMismatchException ArithmeticException DividedByZeroException QUESTION 19 Suppose we had the following method header: public void someMethod (int someNumber) Which of the following is an overloaded version of this method? public void someMethod (int someNumber, int anotherNumber) O public int someMethod (int anotherNumber) O public void someMethod (int anotherNumber) public void anotherMethod (int...

  • This is the assignment..... Write a class DataSet that stores a number of values of type...

    This is the assignment..... Write a class DataSet that stores a number of values of type double. Provide a constructor public DataSet(int maxNumberOfValues) and a method public void addValue(double value) that add a value provided there is still room. Provide methods to compute the sum, average, maximum and minimum value. ​This is what I have, its suppose to be using arrays also the double smallest = Double.MAX_VALUE; and double largest = Double.MIN_VALUE;​ are there so I don't need to create...

  • I need help with the following Java code Consider a class Fraction of fractions. Each fraction...

    I need help with the following Java code Consider a class Fraction of fractions. Each fraction is signed and has a numerator and a denominator that are integers. Your class should be able to add, subtract, multiply, and divide two fractions. These methods should have a fraction as a parameter and should return the result of the operation as a fraction. The class should also be able to find the reciprocal of a fraction, compare two fractions, decide whether two...

  • ​I have to create two classes one class that accepts an object, stores the object in...

    ​I have to create two classes one class that accepts an object, stores the object in an array. I have another that has a constructor that creates an object. Here is my first class named "ShoppingList": import java.util.*; public class ShoppingList {    private ShoppingItem [] list;    private int amtItems = 0;       public ShoppingList()    {       list=new ShoppingItem[8];    }       public void add(ShoppingItem item)    {       if(amtItems<8)       {          list[amtItems] = ShoppingItem(item);...

  • i need help fixing my code. here is the assignment: Make a class that contains the...

    i need help fixing my code. here is the assignment: Make a class that contains the following functions: isLong, isDouble, stringToLong, and stringToDouble. Each receives a string and returns the appropriate type (bool, bool, long, and double).During the rest of the semester you will paste this class into your programs and will no longer use any of the "standard" c# functions to convert strings to numbers. here is my code. it works for the long method but not the double:...

  • Please answer all the questions thank you 1) (Classes – 20 Points) Consider the following class...

    Please answer all the questions thank you 1) (Classes – 20 Points) Consider the following class declaration for Time to complete the questions below: DO NOT WRITE MORE THAN ASKED FOR. class Time private: int hours; int minutes; public: Time(); Time (int , int m = 0); void addMin(int m); void addHr(int h); void reset(int h = 0, int m = 0); Time operator+(const Time & t) const; Time operator-(const Time & t) const; Time operator*(double n) const; friend Time...

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
ADVERTISEMENT