Passing reference type values as method parameters

One important difference between the reference types and primitive types that merits special discussion is the way their values can be used in a method. Let's see the difference by example. First, we create the SomeClass class:

class SomeClass{  private int count;  public int getCount() {    return count;  }  public void setCount(int count) {      this.count = count;    }}

Then we create a class that uses it:

public class ReferenceTypeDemo {  public static void main(String[] args) {    float f = 1.0f;    SomeClass someClass = new SomeClass();    System.out.println("\nBefore demoMethod(): f = " + f +                              ", count = " + someClass.getCount());    demoMethod(f, someClass);    System.out.println("After demoMethod(): f = " + f ...

Get Introduction to Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.