Class Notes (1,100,000)
US (490,000)
Cornell (1,000)
CS (100)
CS 2110 (30)
Gries (30)
Lecture 2

CS 2110 Lecture 2: Lecture 2 - Objects


Department
Computer Science
Course Code
CS 2110
Professor
Gries
Lecture
2

This preview shows half of the first page. to view the full 2 pages of the document.
Lecture 2 - Objects
oLike in Python, parameter is the variable inside a method
Argument is when you call the method
oCreating a new object
new javax.swing.JFrame()
This is just an example
Creates a JFrame Object.
Value of this expression is a pointer to the new object
JFrame@25c7f37d for example is the value
Example
First write javax.swing.JFrame h;
This lets us know the type for h
Then write h = new javax.swing.JFrame()
Now the object name is stored in h
oNote: Procedure is a method that does not return a value
oTo call methods from outside, you do h.<method>()
oSpecifications BEFORE you write class definition.
NOT LIKE PYTHON
&^^^^^^^^
^^^^
REMEMBER THAT
oNote: You’re declaration of your variable can be made shorter by combining the
two lines
Remember for an int
Int x;
x = 5
Now we can combine the two
int x = 5
oSo for class definitions, if we want to make something of class CC for example
CC g= new CC();
Creates variable g, stores the object of type CC’s name in g
oSubclasses
If we do public class CC extends javax.swing.JFrame {...}
We get C as a subclass of JFrame
WOAAAAAAAAAAAAAAAH
oDeclaring methods in class definitions
Functions:
Inside the braces {...}, you
1. First comment /** … */
2. Write public int area() {...}
int is the type of value the function will return
area is the name of the function
Parameters go in parentheses
3. Write return <whatever you want to return> inside the braces
OF THE FUNCTION {...}
Ex: return getWidth() * getHeight();
find more resources at oneclass.com
find more resources at oneclass.com
You're Reading a Preview

Unlock to view full version