Lecture An introduction to computer science using java (2nd Edition): Chapter 10 - S.N. Kamin, D. Mickunas, E. Reingold

Chapter 10 - Classes and Methods IV: Static methods and variables. In this chapter we will: introduce class variables and class methods, discuss overloading for class methods, introduce Java interfaces which specify object behavior, discuss the use of methods to modularize large programs, illustrate process of stepwise program refinement. | Chapter 10 Classes and Methods IV: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by . Kamin, D. Mickunas, E. Reingold Chapter Preview In this chapter we will: introduce class variables and class methods class variables have only one instance and are not contained in any object class methods have no receiver and can only access class variables discuss overloading for class methods introduce Java interfaces which specify object behavior discuss the use of methods to modularize large programs illustrate process of stepwise program refinement Class Variables Associated with a class, not class instance Only one instance of each class variable, not one instance per object Created by adding the modifier static to the variables declaration Allows variables to be modified once for all class objects Can be accessed by class methods Class Methods Methods declared with static modifier Can be defined in any class Not associated with an object Is not invoked by sending it as a message to an object The class method f in the class C is invoked using the notation ( ) It has no receiver and cannot refer to instance variables It can refer to and manipulate class variables Classes with No Instance Variables or Methods Some classes only contain class variables and methods Since these classes have no instance variables they need no constructors Provide a convenient way of packaging collections of useful methods Some collections like Math define symbolic constants that are unchangable public static final double E = public static final double PI = methods are all declared to be public and static these methods operate only on built-in data types Classes without Instance Methods Class ClassnameClient { // Author, date, expalnation public static void main (String[ ] args { Classname variable = new Classname( ); variable, method( ); } } Sformat Class Purely static class taken from CSLib Contains a number of | Chapter 10 Classes and Methods IV: Static Methods and Variables Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by . Kamin, D. Mickunas, E. Reingold Chapter Preview In this chapter we will: introduce class variables and class methods class variables have only one instance and are not contained in any object class methods have no receiver and can only access class variables discuss overloading for class methods introduce Java interfaces which specify object behavior discuss the use of methods to modularize large programs illustrate process of stepwise program refinement Class Variables Associated with a class, not class instance Only one instance of each class variable, not one instance per object Created by adding the modifier static to the variables declaration Allows variables to be modified once for all class objects Can be accessed by class methods Class Methods Methods declared with static modifier Can be defined in any class Not .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã 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.