go to previous page   go to home page   go to next page

Answer:

First  value of the result: 0
Second value of the result: 14

Object References as Parameters

Object references can be parameters. Call by value is used, but now the value is an object reference. This reference can be used to access the object and possibly change it. Here is an example program:

In this program, the local variable message contains a reference to a String object. That reference is the value that is copied into the formal parameter st of the print() method. The object itself is not copied.


class ObjectPrinter
{
  public void print( String st )
  {
    System.out.println("Value of parameter: " + st );    
  }
}

class OPTester
{
  public static void main ( String[] args )
  {
    String message = "Only One Object" ;

    ObjectPrinter op = new ObjectPrinter();

    System.out.println("First  value of message: " + message );    
    op.print( message );
    System.out.println("Second value of message: " + message );    
  }
}

QUESTION 6:

What is the output of the program?

First  value of message: 
Value of parameter: 
Second value of message: