INEHRITANCE IN JAVA PROGRAMMING!
INEHRITANCE IN JAVA PROGRAMMING!
Inheritance is one of the most important characteristic of object oriented programming language. It is the mechanism by which one class access the property like variable or field and method of another class. The class which inherits the main class is called Derived Class and which gets inherited is called Derived Class. The following is the simple example of inheritance in which class Division and Multiplication access the field of Calculation Class and then calculates the multiplication and division.
package Inheritance;
public class MainClass {
public static void main(String[] args) {
Multiplication mul= new Multiplication();
Division div= new Division();
mul.value(10, 5);
div.value(10, 5);
System.out.println(mul.multiply());
System.out.println(div.divide());
}
}
package Inheritance;
public class Calculation {
protected int a;
protected int b;
public void value(int m, int n){
a=m;
b=n;
}
}
package Inheritance;
public class Multiplication extends Calculation {
public double multiply() {
return (a*b);
}
}
package Inheritance;
public class Division extends Calculation {
public double divide() {
return (a/b);
}
}
Here's the output of the code:
Leave INEHRITANCE IN JAVA PROGRAMMING! to:
Read more #hive-122108 posts
Best Posts From Leo Umesh
We have not curated any of leoumesh's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From Leo Umesh
- The Tattoo of My Newborn Baby Girl Forever Inked on My Skin
- Long Weekend Food Feast With Wife
- String Manipulation in C#: Part 2
- String Manipulation in C#
- Introduction to C# and .NET
- Weekend Escape To Falls
- Evening Barbecue With Favourite Beer 🍺 🍻
- NumPy Broadcasting
- Summer BBQ
- Review of "The Day of The Jackal" Series
- Wonders of Wave Rock, Western Australia
- Trying To Make Authentic Chicken Dum Biryani At Home
- Beautiful Ocean Lookout in South West Australia
- Esperance: Hidden Paradise of Western Australia
- Cruising Through Blue Haven Beach
- My First Tattoo
- Exploring Flavoursome Veggie Indian Cuisines
- Australia's Popular Drink: Homemade
- An Everlasting Flowers
- Unexpected Rainbow At Wellington Dam, Western Australia