TAILIEUCHUNG - Object-Oriented Programming: Inheritance

Object-Oriented Programming: Inheritance includes Inheritance, Overriding and hiding methods, Polymorphism, Final methods and classes, Abstract methods and classes; In Java, excepting Object, every class has one and only one direct superclass. | Lecture 5: Inheritance Lê Hồng Phương phuonglh@ Department of Mathematics, Mechanics and Informatics, Vietnam National University, Hanoi Content ● Inheritance ● Overriding and hiding methods ● Polymorphism ● Final methods and classes ● Abstract methods and classes 2012-2013 Object-Oriented Programming: Inheritance 2 Inheritance ● ● ● A class that is derived from another class is called a subclass (derived class, extended class, child class). The superclass is also called base class or parent class. In Java, excepting Object, every class has one and only one direct superclass. 2012-2013 Object-Oriented Programming: Inheritance 3 Inheritance ● ● ● A subclass inherits all the members (fields, methods, and nested classes) from its superclass. Constructors are not members, so they are not inherited by subclasses. The constructor of the superclass can be invoked from the subclass. 2012-2013 Object-Oriented Programming: Inheritance 4 Inheritance public class Bicycle { private int cadence = 0; private int speed = 0; private int gear = 1; } The fields represent the state of the object. void changeCadence(int newValue) { cadence = newValue; } void changeGear(int newValue) { The methods define its gear = newValue; interaction with the outside world. } void speedUp(int increment) { speed = speed + increment; } void applyBrakes(int decrement) { speed = speed - decrement; } void printStates() { ("(" + cadence + ", " + speed + ", " + gear + “)”); } 2012-2013 Object-Oriented Programming: .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.