CC2203-les02javaII-1011s2-for-viewing

CC2203-les02javaII-1011s2-for-viewing - 2-1/21Lesson 2:...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

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

Unformatted text preview: 2-1/21Lesson 2: Java II – Classes and ObjectsAfter completing this lesson, you should be able to do the following:•Define instance variables and methods•Define the no-arg (default) constructor method•Instantiate classes and call instance methods•Perform encapsulation by using packages to group related classes•Control access with publicand privateaccess modifiers•Use packages to group related classes•Use class variables and methods2-2/21title: “Gone with…”rating: “PG”title: “Last Action…”rating: “PG-13”Comparing Classes and Objectspublic void displayDetails()private String title;private String rating;public void setRating()Movie•An object is an instance of a class.•Objects have their own memory.•Class definitions must be loaded to create instances.mov1mov2[demonstration – javaII.zip]2-3/21Creating Objects•Objects are typically created by using the newoperator:•For example, to create two Movie objects:Movie mov1 = new Movie("Gone ...");Movie mov2 = new Movie("Last ...");ClassName objectRef = new ClassName();title: “Gone with…”rating: “PG”title: “Last Action…”rating: “PG-13”2-4/21title: “Gone with…”rating: “PG”Using the newOperatorThe newoperator performs the following actions:•Allocates and initializes memory for the new object•Calls a special initialization method in the class, called a constructor•Returns a reference to the new objectMovie mov1 = new Movie("Gone with…");mov1(when instantiated)2-5/21Comparing Primitives and ObjectsPrimitive variables hold a value....
View Full Document

This note was uploaded on 08/18/2011 for the course COMP 3868 taught by Professor Keithchan during the Summer '97 term at Hong Kong Polytechnic University.

Page1 / 21

CC2203-les02javaII-1011s2-for-viewing - 2-1/21Lesson 2:...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online