Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Java - Method Overriding
WhatsApp
Senthilvelan Sambamoorthy
5y
3.9
k
0
0
25
Blog
Introduction
In this blog, I will explain about the Method Overriding concept in Java. It is very simple in Java programming. The output will be displayed in the Run module.
Software Requiremen
t
JDK1.3.
Overriding
The benefit of overriding is the ability to define a behavior, which is specific to the subclass type, which means a subclass can implement a parent class method, based on its requirement. In object-oriented terms, overriding means to override the functionality of an existing method.
Simple program
class
circle {
double
r;
circle() {
r =
10
;
}
void
getarea() {
double
a;
a = (
3.14
* r * r);
System.out.println(
"\nArea of Circle is : "
+ a);
}
}
class
cylinder
extends
circle {
double
r, h;
cylinder(
double
rad,
double
height) {
r = rad;
h = height;
}
void
getarea() {
double
a;
a = (
3.14
* r * r * h);
System.out.println(
"\nArea of Cylinder is : "
+ a);
}
}
class
area {
public
static
void
main(String arg[]) {
circle c =
new
circle();
cylinder l =
new
cylinder(
5
,
10
);
circle re;
re = c;
re.getarea();
re = l;
re.getarea();
}
}
Explanation
In this blog, I explained about Method Overriding concept in Java programming. The output will be displayed in the Run module.
Output
Method Overriding
Java
Up Next
Implementation Of Remote Method Invocation Concept In Java
Ebook Download
View all
Programming in Java
Read by 670 people
Download Now!
Learn
View all
Membership not found