Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Java Passing References and Point Class - Prof. Brian F. Hanks, Study notes of Javascript programming

The concept of passing references in java, using the examples of demo3.java and passingreferences.java. It explains that all types are passed by value, but if a reference type's value is changed, the change is reflected back in the caller. The document also introduces instance methods and the point class, which requires methods for constructors, accessors, mutators, and a tostring() method.

Typology: Study notes

Pre 2010

Uploaded on 08/05/2009

koofers-user-3jl-1
koofers-user-3jl-1 🇺🇸

10 documents

1 / 2

Toggle sidebar

Related documents


Partial preview of the text

Download Java Passing References and Point Class - Prof. Brian F. Hanks and more Study notes Javascript programming in PDF only on Docsity! CSIS 110 – Lecture 27 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] <returnType> <Identifier> ( <Parameter List> ) <MethodBody> So: class method -- use static instance method - no static Let's create a class Point that represents points on a two dimensional grid. Each point has an x and y coordinate. What methods do Points need?
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved