Methods


  1. What is the output of this program?

    class equal
    {
    int p;
    int q;
    boolean isequal()
    {
    return(p == q);
    }
    }
    public class Result
    {
    public static void main(String args[])
    {
    equal equ = new equal();
    equ.p = 7;
    equ.q = 5;
    System.out.println(equ.isequal());
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    Output: false


  1. What is the output of this program?

    class box_Shape
    {
    int w;
    int h;
    int l;
    int vol;
    void vol()
    {
    vol = w * h * l;
    }
    void vol(int p)
    {
    vol = p;
    }
    }
    public class Result
    {
    public static void main(String args[])
    {
    box_Shape bs = new box_Shape();
    bs.h = 2;
    bs.l = 7;
    bs.w = 6;
    bs.vol(6);
    System.out.println(bs.vol);
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Output: 6



  1. Which of these keyword can be used in subclass to call the constructor of superclass?











  1. View Hint View Answer Discuss in Forum

    None of these

    Correct Option: D

    super


  1. What is the process of defining a method in subclass having same name & type signature as a method in its superclass?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Method overriding



  1. Which of these keywords can be used to prevent Method overriding?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    To disallow a method from being overridden, specify final as a modifier at the start of its declaration. Methods declared as final cannot be overridden.