Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Summary

Summary Learn Java

Rating
-
Sold
-
Pages
2
Uploaded on
22-09-2024
Written in
2024/2025

Learn Java and try these examples for your better understanding of Java and improve your skills in Java

Institution
Course

Content preview

Q)What is method overriding?
=>Redefining the super class method in sub class is known as method overriding.
=>When method overriding is implemented, super class version of the method is known as
an overridden method.Sub class version of the method is known as an overriding method.
For eg.
class Vehicle{
void move(){
}//overridden method
}//super class
class Car extends Vehicle{
void move(){
}//overriding method
}//sub class

Note:- When method overriding is implemented, if the method is called on the sub class object, always ov
erriding method only is executed but not the overrdden method.

=>Method overriding is implemented in the following scenarios.
1.)Parent class provided functionality is not required in child class. Method name reusability is required
for the sub class object but not the code reusability.

2.)Super class provided functionality is required but insufficient for the sub class object.To add some
more functionality in the sub class under the same method name.

3.)Parent class has given only method name but no code(abstract method concept)

=>There are four rules to be followed in order to implement method overriding.
1)signature of both the methods should be the same.
2)Return type of the methods should be the same.
3)Overriding method should not have weaker access privileges(equal is ok and more also ok)
4)Overriding method should not have those checked exceptions in the throws clause that are not specifi
ed in the Overridden method’s throws clause.

Q)Example program on method overriding.
//MethodOverridingApplication.java
class Vehicle{
void move(){
System.out.println("Every vehicle should move this way");
}//overridden method
}//super class

class Car extends Vehicle{
void move() {
System.out.println("As a car I move in my own way");
}//overriding method
}//sub class

class MethodOverridingApplication{
public static void main(String[] args){
Car c=new Car();
c.move();
}
}
**************************
//MethodOverridingApplication2.java

Written for

Institution
Course

Document information

Uploaded on
September 22, 2024
Number of pages
2
Written in
2024/2025
Type
SUMMARY

Subjects

$5.39
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
saiteja4

Get to know the seller

Seller avatar
saiteja4 Swami Vivekanand institution
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
10
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions