Home » JAVA Programming » Methods » Question
  1. What is the output of this program?

    class method
    {
    int p;
    double q;
    void add(int n1 , int n2)
    {
    p = n1 + n2;
    }
    void add(double n3 , double n4)
    {
    q = n3 + n4;
    }
    method()
    {
    this.p = 0;
    this.q = 0;
    }
    }
    public class method_overload
    {
    public static void main(String args[])
    {
    method obj = new method();
    int n1 = 5;
    double n2 = 7.5;
    obj.add(n1, n1);
    obj.add(n2, n2);
    System.out.println(obj.p + " " + obj.q);
    }
    }
    1. 10 15.0
    2. 10.0 15
    3. 15 10
    4. 10.0 15.0
    5. None of these
Correct Option: A

Output: 10 15.0



Your comments will be displayed only after manual approval.