JAVA_3 - Introduction to Classes and Objects and using your...

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

View Full Document Right Arrow Icon
and using your own classes. The first four of these examples begin our case study on developing a grade-book class that instructors can use to maintain student test scores. This case study is enhanced over the next several chapters, culminating with the version presented in Chapter 7 , Arrays. The last example in the chapter introduces floating-point numbersthat is, numbers containing decimal points, such as 0.0345, 7.23 and 100.7in the context of a bank account class that maintains a customer's balance . 3.2 . Classes, Objects, Methods and Instance Variables 3.3 . Declaring a Class with a Method and Instantiating an Object of a Class Figure 3.1. Class declaration with one method . 1 // Fig. 3.1: GradeBook.java 2 // Class declaration with one method . 3 4 public class GradeBook 5 } 6 // display a welcome message to the GradeBook user 7 public void displayMessage () 8 } 9 System.out.println( "Welcome to the Grade Book "! ;( 10 // { end method displayMessage 11 12 // { end class GradeBook Figure 3.2. Creating an object of class GradeBook and calling its displayMessage method . 1 // Fig. 3.2: GradeBookTest.java 2 // Create a GradeBook object and call its displayMessage method . 3 4 public class GradeBookTest 5 } 6 // main method begins program execution 7 public static void main( String args ( [] 8 }
Background image of page 1

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

View Full DocumentRight Arrow Icon
OBJECTIVES In this chapter you will learn : What classes, objects, methods and instance variables are . How to declare a class and use it to create an object . How to declare methods in a class to implement the class's behaviors . How to declare instance variables in a class to implement the class's attributes . How to call an object's method to make that method perform its task . The differences between instance variables of a class and local variables of a method . How to use a constructor to ensure that an object's data is initialized when the object is created . The differences between primitive and reference types . 3.1 . Introduction We introduced the basic terminology and concepts of object-oriented programming in Section 1.16 . In Chapter 2 , you began to use those concepts to create simple applications that displayed messages to the user, obtained information from the user, performed calculations and made decisions. One common feature of every application in Chapter 2 was that all the statements that performed tasks were located in method main . Typically, the applications you develop in this book will consist of two or more classes, each containing one or more methods. If you become part of a development team in industry, you might work on applications that contain hundreds, or even thousands, of classes. In this chapter, we present a simple framework for organizing object-oriented applications in Java . First, we motivate the notion of classes with a real-world example. Then
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/14/2011 for the course MATH 401 taught by Professor H.ayad during the Spring '11 term at Cairo University.

Page1 / 18

JAVA_3 - Introduction to Classes and Objects and using your...

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

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