filmov
tv
Learn Java Programming - Introduction to Inheritance Tutorial
Показать описание
Inheritance is one of the key components to understanding object-oriented programming. The word inheritance implies receiving certain possessions upon the death of a family member or a close friend. In real life, one can draw up a will specifying who will receive a possession and who will not. One can even designate that possessions can be shared or even say that nobody can have them. Many lawyers make a decent living writing up wills and acting as an executor.
In Java, the concept of inheritance is similar; the relatives are the classes, the possessions are its members, the family is a package. A will specifies the ownership and access to possessions, whereas in Java, the ownership and access to class members is handled by access modifiers. There is one major difference between real life and Java - no classes have to die for inheritance to occur. The topic of inheritance is quite extensive and will apply to many advanced features of Java. The goal of this tutorial is to lay the first building block in the foundation of understanding inheritance - the extends keyword.
The extends keyword 'ties' the members of a parent class to a child class. The extends keyword is placed after the name of the child class and before the name of the parent class that we are inheriting from. The parent class is known as the superclass and the child class is known as the subclass.
In Java, the concept of inheritance is similar; the relatives are the classes, the possessions are its members, the family is a package. A will specifies the ownership and access to possessions, whereas in Java, the ownership and access to class members is handled by access modifiers. There is one major difference between real life and Java - no classes have to die for inheritance to occur. The topic of inheritance is quite extensive and will apply to many advanced features of Java. The goal of this tutorial is to lay the first building block in the foundation of understanding inheritance - the extends keyword.
The extends keyword 'ties' the members of a parent class to a child class. The extends keyword is placed after the name of the child class and before the name of the parent class that we are inheriting from. The parent class is known as the superclass and the child class is known as the subclass.
Комментарии