answersLogoWhite

0

Example of overriding in java

Updated: 8/11/2023
User Avatar

Wiki User

14y ago

Best Answer

For example:

class Speak

{

void SayHello(){};

}

class Boy extends Speak

{

void SayHello(){System.out.println("I'm a boy");}

}

So overriding is usual to rewrite the motheds in subclasses .In subclsses ,you can override the methods acceded from his parent class.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

No. Overriding is not possible without Inheritance

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Example of overriding in java
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

When do you declare a method or class abstract in java?

when overriding of a class or a method is necessary, they can be declared as abstract


What is the difference between overloading and overriding methods in object?

Here are some of the most common differences between both of them. If you are working in Java for more than 1 year, you might be familiar with all of them but any way its good revision: 1) First and major difference between Overloading and Overriding is that former occur during compile time while later occur during runtime. 2) Second difference between Overloading and Overriding is that, you can overload method in same class but you can only override method in sub class. 3) Third difference is that you can overload static method in Java but you can not override static method in Java. In fact when you declare same method in Sub Class it's known as method hiding because it hide super class method instead of overriding it. 4) Overloaded methods are bonded using static binding and Type of reference variable is used, while Overridden method are bonded using dynamic bonding based upon actual Object. 5) Rules of Overloading and Overriding is different in Java. In order to overload a method you need to change its method signature but that is not required for overriding any method in Java.


It is an error to have a method with the same signature in both the super class and its subclass. True or false?

False. A method with the same signature in both the superclass and its subclass is known as method overriding, and is a valid concept in Java.


What are overriding objectives?

The objective of overriding in Java is to provide features for a class to define its own behavior even for cases where the super class that it extends has already defined one. There might be cases where we want a specific behavior in our class but if the super class already has a method that does the same thing we wont be able to implement our behavior. Hence this overriding concept is available which lets us write our own implementation which would mask the code in the super class and let us run our logic.


How are java program statements terminated?

Each statement in Java ends with a semicolon, for example: int a; a = 5; int b = 10;

Related questions

What is overriding method in java with simple example?

ye bohut mushkil sawa lhai


What is a operator overriding in java?

Java does not support object overriding. It does support operator overloading by means of the "+" symbol which is used for both numeric addition as well as string concatenation.


When do you declare a method or class abstract in java?

when overriding of a class or a method is necessary, they can be declared as abstract


What is method overriding and overloading in java?

Overloading is the means by which we can provide two or more different definitions of the same method in the same namespace. Overriding is the means by which a derived class may redefine the meaning of a base class method.


What is the difference between overloading and overriding methods in object?

Here are some of the most common differences between both of them. If you are working in Java for more than 1 year, you might be familiar with all of them but any way its good revision: 1) First and major difference between Overloading and Overriding is that former occur during compile time while later occur during runtime. 2) Second difference between Overloading and Overriding is that, you can overload method in same class but you can only override method in sub class. 3) Third difference is that you can overload static method in Java but you can not override static method in Java. In fact when you declare same method in Sub Class it's known as method hiding because it hide super class method instead of overriding it. 4) Overloaded methods are bonded using static binding and Type of reference variable is used, while Overridden method are bonded using dynamic bonding based upon actual Object. 5) Rules of Overloading and Overriding is different in Java. In order to overload a method you need to change its method signature but that is not required for overriding any method in Java.


What are benefits of array in java?

array example in java


Can we say bank transaction is one of the real time example to method overriding in java?

yes. we can sat . because the same method may be used by many banks but implementations may be different. Eg: withDraw(int i) { int maxWithDraw = 10000; if(i>maxWithDraw) { Sop("Not allowed"); } } Eg: withDraw(int i){ ** int maxwithDraw = 20000; ....... } Here we can see that the methods are the same but implementation is different. This is nothing but overriding.


Why use function overriding in Java?

You use function overriding in Java when you inherit a bunch of features from a class and for a few particular cases alone, you do not wish to use the functionality of the parent class and wish to implement a custom feature in your class. In such cases, you create a method in your class with the same name and signature as in your parent class, thereby overloading it. this way only your current class will be used by the JVM unless specifically invoked by using the super keyword.


Which of thewould be an example of a check of the presidents power?

Congress overriding a presidential veto with a 2/3 vote


Make a sentence with the word overriding?

Your safety is our overriding consideration.


It is an error to have a method with the same signature in both the super class and its subclass. True or false?

False. A method with the same signature in both the superclass and its subclass is known as method overriding, and is a valid concept in Java.


How can find the length of a string in java without using fun?

Use length() method. Example: "java".length();