Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
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
Java
Method Overriding
Up Next
Implementation Of Remote Method Invocation Concept In Java
Ebook Download
View all
Programming in Java
Read by 629 people
Download Now!
Learn
View all
Membership not found