How parameters are passed in Java..PDF

How parameters are passed in Java.

. What is the output of the following Java program? Explain in terms of how parameters are passed in Java. import java.awt.*; class PointParameters { public static void main(String [] args) { int x = 1, y = 1; Point p = new Point(x, y), q = new Point(x, y); doubleScale(x, y, p, q); System.out.println( "(x,y) = " + new Point(x, y) + " p = " + p + " q = " + q); } private static void doubleScale(int x, int y, Point p, Point q) { x *= 2; y *= 2; p.x *= 2; p.y *= 2; q = new Point(x, y); } } Suppose a similar program were written in C# in which all the parameters were ref parameters. What would the output of that program be? 2. Examine the following C++ program, in which a IntList class is defined that contains an overloaded [] operator. What is the output of this program? #include using name std; class IntList { private: int list[1]; public: IntList() {list[0] = 0;} int& operator[] (const int index) {return list[index];} }; int main() { IntList list; cout << list[0] << endl; list[0] = 1; cout << list[0] << endl; return 0; } Notice that the overloaded [] operator returns a reference. Change the [] operator to return a value instead and explain what happens in that case. Explain why the ability to return by reference is essential to be able to implement such an operator. Can anything similar be done in Java?
Powered by