Java – class inheritance | superclass and subclass

Java – class inheritance | superclass and subclass

In Java a class can inherit another class. The inherited class is called Superclass and the class that inherits another class it is called subclass. syntax: puplic class subclassName extends superclassName{ additional fields and methods or method overriding } The subclass should only declare new fields, implement new methods or override superclass methods. All the variables and methods of the superclass are inherited automatically. As you see on the example above, the subclass’s constructor called the superclass constructor using the super keyword. This is important. The subclass must initialize the…

Java – class inheritance | superclass and subclass Read More

Kotlin – Classes Part 2 Inheritance

Screenshot 20190123 133806

Let’s say we have the following class: If you want to learn more about the code above, read Part 1 Now, if you want this class to be inherited or extended, you need to tell that to Kotlin. You can do that with open. In Kotlin all the classes are final. That means that the classe cannot be subclassed. Now you can extend or inherit this class You need to initialize the class here because it has a primary constructor. That is why Suv class has one parameter, and pass…

Kotlin – Classes Part 2 Inheritance Read More