Lecture Java: Chapter 4

Lecture Java: Chapter 4 (Writing Classes) focuses on: Class definitions, instance data, encapsulation and Java modifiers, method declaration and parameter passing, constructors, graphical objects, events and listeners, buttons and text fields. | Copyright © 2012 Pearson Education, Inc. Chapter 4 Writing Classes Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus Writing Classes We've been using predefined classes from the Java API. Now we will learn to write our own classes. Chapter 4 focuses on: class definitions instance data encapsulation and Java modifiers method declaration and parameter passing constructors graphical objects events and listeners buttons and text fields Copyright © 2012 Pearson Education, Inc. Outline Anatomy of a Class Encapsulation Anatomy of a Method Graphical Objects Graphical User Interfaces Buttons and Text Fields Copyright © 2012 Pearson Education, Inc. Writing Classes The programs we’ve written in previous examples have used classes defined in the Java standard class library Now we will begin to design programs that rely on classes that we write ourselves The class that contains the main method is just the starting point of a program True . | Copyright © 2012 Pearson Education, Inc. Chapter 4 Writing Classes Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus Writing Classes We've been using predefined classes from the Java API. Now we will learn to write our own classes. Chapter 4 focuses on: class definitions instance data encapsulation and Java modifiers method declaration and parameter passing constructors graphical objects events and listeners buttons and text fields Copyright © 2012 Pearson Education, Inc. Outline Anatomy of a Class Encapsulation Anatomy of a Method Graphical Objects Graphical User Interfaces Buttons and Text Fields Copyright © 2012 Pearson Education, Inc. Writing Classes The programs we’ve written in previous examples have used classes defined in the Java standard class library Now we will begin to design programs that rely on classes that we write ourselves The class that contains the main method is just the starting point of a program True object-oriented programming is based on defining classes that represent objects with well-defined characteristics and functionality Copyright © 2012 Pearson Education, Inc. Examples of Classes Copyright © 2012 Pearson Education, Inc. Classes and Objects Recall from our overview of objects in Chapter 1 that an object has state and behavior Consider a six-sided die (singular of dice) It’s state can be defined as which face is showing It’s primary behavior is that it can be rolled We represent a die by designing a class called Die that models this state and behavior The class serves as the blueprint for a die object We can then instantiate as many die objects as we need for any particular program Copyright © 2012 Pearson Education, Inc. Classes A class can contain data declarations and method declarations int size, weight; char category; Data declarations Method declarations Copyright © 2012 Pearson Education, Inc. Classes The values of the data define the state of an object created from the class The

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
463    20    1    27-11-2024
272    22    1    27-11-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.