

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Last time we looked at some class methods, and what happens when the methods are called. Our last example looked what happens when the FP are a reference type. Let's look at Demo3.java And at PassingReferences.java All types are passed by value - it does not matter if the type of the formal parameter is a primitive type or a reference type. This means that if we change the value of a formal parameter, that change is not reflected back in the calling method. However , Let’s look at another example: PassingReferences2.java So, we can see that method f is working with a distinct JFrame, but method g is working with the reference that was passed to it. Repeat KEY POINT: If we change the value that is referenced by a reference type, that change is reflected back in the caller. This is a subtle but important distinction! Instance Methods Remember, instance methods require an object - we invoke instance methods using an object's name followed by '.' and the method name. String s = "Hello"; int l = s.length(); JFrame myFrame = new JFrame( "The Title" ); myFrame.setSize( 200, 300 ); Instance methods are defined without the keyword 'static': [public]