Posts

Showing posts from October, 2023

Method overriding in java. In English

Image
                        Method Overriding A method that is already given by one of a subclass's super-classes or parent classes can be specifically implemented by a subclass or child class in Java by using a feature called overriding. It is said that a method in a subclass "override" a method in the superclass when both methods share the same name, the same parameters or signature, and the same return type. One way Java implements Run Time Polymorphism is by method overriding. The object that is used to invoke a method will determine which version of it is executed. If a method is invoked by an object of a parent class, the method in the parent class will be utilized; however, if a method is invoked by an object of a subclass, the method in the child class will be used. To put it another way, the type of the object being referenced decides which override method will be called, not the type of the reference variable.  Rules...

Inheritance in Java. In English

Image
                       Inheritance What is java inheritance?................ Inheritance is the transfer of features and behaviors from the superclass to the subclass.  It is possible for Java classes to inherit methods and attributes from one another. Two categories make up the "inheritance concept". Subclass (child) - the class that has other classes as inheritors. Superclass (Parent) - the class that is being inherited from. All subclasses share the code defined in the Superclass. The parent class code can be used directly by child classes. Only inheritance allows for Method Overriding. It is one approach for Java to implement run-time polymorphism. Inheritance allows us to reach the concept of abstraction, where we are not need to disclose all the details. Abstraction only makes the user aware of the capability. Use the extends keyword to inherit from a class. Syntax:          ...