![]() So we can see we have both right here, and our editor is allowing us to use both. We can see here that as we begin to type, it's offering us methods of Bicycle, and it's also offering us methods and properties of tandemBike. As we go down here, our editor gives us suggestions, so helps us code. After we instantiate tandemBike, we can see that my2Bike is instantiated and is a type of tandemBike. We can see here again that tandemBike is inheriting from Bicycle. We take a look at our editor, and we have used a visual editor. Things like set the number of gears, get the number of gears. ![]() We would want to obviously keep that in the tandemBike class while still being able to return some of the methods and some of the properties of Bicycle. Number of seats number of seats would be something specific to tandemBike. But here we can see that tandemBike has some of its own. Now tandemBike has all of the properties and methods of Bicycle. That means that tandemBike is the super-class of Bicycle, and Bicycle would be the subclass because it's the foundational or the base class. We can see the extends keyword right here. The class tandemBike is inheriting from Bicycle. Anytime there is a general and specific relationship, there's always an opportunity for inheritance. If we take a look at these two classes, Bicycle and tandemBike, obviously tandemBike is a type of Bicycle, so you can see the relationship there. We can get to market faster and we can have a better product. Inheritance and polymorphism not only can save us time and effort, but they can increase quality. But if we think about it, if there is a class out there that has the properties, methods, features we need, chances are that that code's already been approved, it's already been tested. If we think about that reuse again, if there is a class that already has the desired functionality, there's no need to rewrite it, so again, saving us time and effort. So that's important, saves us time, effort and energy. Also inheritance supports the ability to reuse existing features and functionality. Every time we instantiate an object, we are inheriting the classes, properties, and methods. ![]() Inheritance is a big part, an important part of object oriented programming. Inheritance is implemented using the keyword extends, and that extends keyword is in the class header just to the left of the class from which we are inheriting. Java supports inheritance and polymorphism in a similar way to C++, if not identical to C++ and other object oriented programming languages. This is module three, Java inheritance and polymorphism. Welcome back to this course, Java as a second language. It is recommended that you take these courses in order because the knowledge is cumulative. The instructor walks you through the installation of the environment in course 1 of this Specialization. The labs in this course require you to download and install the Java environment. The final module discusses how all of the things we've learned in the previous lessons together will come together for our final lab. We'll also discuss polymorphism and overloading functions before completing a lab and quiz. We'll explain IF statements, Loops, and arrays, and will discuss Switch Statements and the Java Programming Environment.Īfter that, we'll define inheritance and explore how methods and properties are inherited in Java. Next, we'll take a look at Java Control Structures. We'll also explore characters and strings and you'll add a new class in the lab. In this course, we'll take a look at Java data types, discuss what primitive data types are, and explain data classes. This is the second course in the Java as a Second Language Specialization.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |