Lecture 10 - The main() method Must be defined for at least...

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

View Full Document Right Arrow Icon
The main() method Must be defined for at least one class in a program Is where program execution begins Each class in an application can have its own main() method o Useful for testing a class in isolation When you run a class with java ClassName, its bytecode is loaded, and execution starts at its main() o Other classes are loaded as needed, but their main() methods are not used A class need not have a main() method o Such classes can only be invoked by some other class Objects are instantiated from a class definition using the new operator o Uses heap memory An object reference is a variable that “points to” the newly-allocated object o Uses stack memory o Can be changed so it refers to some other object Eg: Point p = new Point(); Constructor Are used to initialize the state of newly created objects Look like methods, but are different: o Have no return type o Must have exactly the same name as the class o Can only be used with new Can be overloaded, like ordinary methods
Background image of page 1

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

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

This note was uploaded on 11/04/2010 for the course CPSC 233 taught by Professor Li during the Fall '09 term at University of Calgary.

Page1 / 3

Lecture 10 - The main() method Must be defined for at least...

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

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