lecture3-1

lecture3-1 - PIC 20A Lecture 3: Objects, Constructors, More...

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

View Full Document Right Arrow Icon
PIC 20A Lecture 3: Objects, Constructors, More on Methods and Variables
Background image of page 1

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

View Full DocumentRight Arrow Icon
What is an object? An object • is an instance of a class • is data held in memory • has its own attributes and behaviors as specified in its class definition • is accessed by object references which hold the value of the object’s memory address
Background image of page 2
What is a constructor? A constructor • is a special method that initializes the instance variables of a newly created object • is called automatically when an object is instantiated (aka created) • can take arguments but no return type, not even void • always has the same name as the className A class may have several constructors
Background image of page 3

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

View Full DocumentRight Arrow Icon
Constructor Notes •A field does not need to be initialized immediately with constructor arguments. • Java provides a default constructor (one which takes no arguments) if no constructor is defined. • If any constructors are defined, Java will not create a default constructor.
Background image of page 4
• Warning : Java allows other methods of the class to have the same name as the class and specified return types. Such methods are not
Background image of page 5

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

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

This note was uploaded on 04/12/2010 for the course PIC PIC 20A taught by Professor Keithouellette during the Spring '09 term at UCLA.

Page1 / 17

lecture3-1 - PIC 20A Lecture 3: Objects, Constructors, More...

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