Menu
Topics Index
...
`

Overloading


If you need explanation Read this topic

If you need Answer Take test on this topic

Overloading
What will be the output of the following program?
public class DemoOnOverloading {
    int input = '\u0021';
    public static void main(String[] args)     {
        DemoOnOverloading object = new DemoOnOverloading();
        object.incrementor(object);
        System.out.print(object.input);
    }
    void incrementor(DemoOnOverloading inputObject) {
         byte a = 6;
         inputObject.input += ++input + ++a + ++inputObject.input;
    }
}

A. Output = 109
B. Output = 21
C. Output = 111
D. Compilation Error
E. Runtime Error
Topic: Is Java Pass by Reference or Pass by Value

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Answer : A
->Assiging the UniCode value to int input
--> then calling the method incrementor and over there creating an object for the class Demon.. to access the input variable
-> then simple pre-increment and short hand operator
inputObject.input = 33 + 34 + 7 + 35 =109

Posted by Deepak Kumar Yadav    2014-05-12 12:52:51


Ans is A. Initially the value of input is 33 and 33 + 34 + 7 + 35  = 109

Posted by Nikhil Sulibhavi    2014-05-12 12:54:34


Congratulations Deepak Kumar Yadav. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-05-13 04:12:43


© meritcampus 2019

All Rights Reserved.

Open In App