C void mainstring args pair pnew pair1020

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ; //return local variable is ok as a new //copy of the value is returned return temp; } int main() { int x=5; int y=10; //”x” value is copied to the “a” // parameter and ”y” value is // copied to “b” parameter int s1=swap(x,y); cout << x << y << s1; return 0; } Java Parameter Variable is Pass by Value – Class Object Variables public class Tester { sta.c Pair swapObject(Pair a) {//Since “a” is a reference value, the // changes made in “a” are visible // outside the func.on. int temp; temp=a.getFirst(); a.setFirst(a.getSecond()); a.setSecond(temp); Pair localV=new Pair(100,101); //return local object is ok as a copy of //the object reference is returned return localV; } public sta.c void main(String args) { Pair p=new Pair(10,20); //object “p” reference value is //copied to the “a” parameter variable Pair returnPair=swapObject(p); System.out.println("Pair.first "+p.getFirst()+" Pair.second: "+p.getSecond()); System.out.println("returnPair: "+r...
View Full Document

This document was uploaded on 03/06/2014 for the course CS 3710 at Memorial University.

Ask a homework question - tutors are online