Lecture2

Lecture2 - Chapter 2 A trip to Objectville Classes and...

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

View Full Document Right Arrow Icon
1 Chapter 2 A trip to Objectville Classes and Objects Conditions and Loops Why Object Oriented Programming What’s the difference between a Class and Object? Instance Variable and methods Dog Size Breed Name Bark()
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 Writing a class with main The two uses of main: (1) to launch/start your Java application (2) to test your real class Example 1: class MyFirstApp{ public static void main(String[] args){ System.out.println(“I Rule!”); System.out.println(“The World”); } } Save MyFirstApp.java Compile Javac MyFirstApp.java Run Java MyFirstApp
Background image of page 2
3 Example 2: one class Movie { String title; String genre; int rating; two void playIt( ) { System.out.println(“Playing the movie”); } } class MovieTestDrive { public static void main(String[] args) { three Movie one = new Movie( ); one.title = “Gone with the Stock”; one.genre = “Tragic”; one.rating = -2; Title Genre Rating Title Genre Rating Title Genre Rating
Background image of page 3

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

View Full DocumentRight Arrow Icon
4 Movie two = new Movie( ); two.title = “Lost in Cubicle Space”; two.genre = “Comedy”; two.rating = 5; two.playIt(); Movie three = new Movie( ); three.title = “Byte Club”; three.genre = “Tragic but ultimately uplifting”; three.rating = 127; } } Save Movie.java MovieTestDrive.java Compile Javac Movie.java Javac MovieTestDrive.java Run Java MovieTestDrive
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 17

Lecture2 - Chapter 2 A trip to Objectville Classes and...

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

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