TAILIEUCHUNG - Lecture Introduction to programming with Java - Chapter 13: Inheritance and polymorphism

This chapter presents the following content: The object class, the equals method, the tostring method, polymorphism, dynamic binding, compilation details, polymorphism with arrays, abstract methods and classes. | Chapter 13 - Inheritance and Polymorphism The Object Class The equals Method The toString Method Polymorphism Dynamic Binding Compilation Details Polymorphism with Arrays Abstract Methods And Classes 1 The Object Class The Object class is a superclass for all other classes. When declaring your own classes, you don't have to specify the Object class as a superclass - it's automatically a superclass. We're covering just two of Object's methods. The equals and toString methods are the most important Object methods. 2 The equals Method For a class that doesn't have its own equals method, if an object from that class calls the equals method, it inherits and uses the Object class's equals method. The Object class's equals method returns true if the two reference variables that are being compared point to the same object; that is, if the two reference variables contain the same address. 3 The equals Method Assuming that the Car class does not have its own equals method, what does this code fragment print? Car car1 = new Car("Honda"); Car car2 = car1; if (((car2) && (car1 == car2)) { ("cars are equal - first time"); } car2 = new Car("Honda"); if (((car2)

Đã 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.