answersLogoWhite

0


Best Answer

Yes, it is perfectly possible. If two methods have a different signature, they can exist together irrespective of where they are present, either in the same class or in a super class, sub class situation.

If two methods have the same signature and one exists in the super class and one in the sub class it is called method overriding.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Is it possible to have a method in the super class and sub class with same name but different signature?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is the scope of method overloading and overriding?

Overloading happens when you have multiple methods in the current class that have the same name but different signature. The scope of method overloading is "Within the current class" Overriding happens when your current class extends another class (the parent class) and provides implementation for a method that is already available in the parent class. The scope of method overriding too is "Within the current class"


Can a private method be overridden?

No. A method that is declared as private in a class is not inherited by any other class and hence if another class that extends this class declares a method with the same name and signature, it does not mean that this method is overridden. It is an entirely separate entity.


What is the purpose of method overriding?

Assuming class A has a method named getXXX() and class B is a sub class of class A. Now, if we write a method with the same name getXXX() in class B, with exactly the same signature as class A, it is called overriding a method. The method getXXX() in class A becomes the overridden method.


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.


Difference between Method overloading and method overriding in C plus plus?

Yes. Any base class method that is declared virtual can be overridden by a derived class. Overriding a method that is not declared virtual can still be called, but will not be called polymorphically. That is, if you call the base class method, the base class method will execute, not the override. To call a non-virtual override you must call it explicitly.

Related questions

How you compare and contrast overloading and overriding methods in java?

Method overloading is when you have multiple methods in a class that have the same name but a different signature. Method overriding is similar to method overloading, with a small difference. In overriding, a method in a parent class is overridden in the child class. The method in the child class will have the same signature as that of the parent class. Since the method in the child class has the same signature & name as the method of its parent class, it is termed as overriding. In situations where you may have to explicitly call the parent class method you can use the "super" keyword and for explicitly calling the current objects method you can use the "this" keyword.


What is the scope of method overloading and overriding?

Overloading happens when you have multiple methods in the current class that have the same name but different signature. The scope of method overloading is "Within the current class" Overriding happens when your current class extends another class (the parent class) and provides implementation for a method that is already available in the parent class. The scope of method overriding too is "Within the current class"


Can a private method be overridden?

No. A method that is declared as private in a class is not inherited by any other class and hence if another class that extends this class declares a method with the same name and signature, it does not mean that this method is overridden. It is an entirely separate entity.


What is the purpose of method overriding?

Assuming class A has a method named getXXX() and class B is a sub class of class A. Now, if we write a method with the same name getXXX() in class B, with exactly the same signature as class A, it is called overriding a method. The method getXXX() in class A becomes the overridden method.


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.


Difference between Method overloading and method overriding in C plus plus?

Yes. Any base class method that is declared virtual can be overridden by a derived class. Overriding a method that is not declared virtual can still be called, but will not be called polymorphically. That is, if you call the base class method, the base class method will execute, not the override. To call a non-virtual override you must call it explicitly.


Explain any 8 difference between overloading and overriding?

Overriding methods that are in the parent class is to redefine them in the current (child) class in a different way. Like if you're extending a class but you don't like the behavior of one method in that class, you can override that method and write your own code. Overloading a method in the current class is defining another copy of the method with different signature. They call them overloaded methods. This is an example of overloaded methods: myMethod(int i, int b){ .... } myMethod(String s) { ... } myMethod(boolean b) {...} Hope that was clear


S it an error to have a method with the same signature in both the super class and its subclass?

No; you may decide to change the behaviour of a method in the subclass, or to add additional functionality.


What is function overriding in Java?

Method overriding is similar to method overloading, with a small difference. In overriding, a method in a parent class is overridden in the child class. The method in the child class will have the same signature as that of the parent class. Since the method in the child class has the same signature & name as the method of its parent class, it is termed as overriding. In situations where you may have to explicitly call the parent class method you can use the "super" keyword and for explicitly calling the current objects method you can use the "this" keyword.


What do you meant by Runtime Polymorphism?

Runtime polymorphism is also called as method overriding, late binding or dynamic polymorphism. It is when a method in a subclass overrides a method in its super class with the same name and signature.


Can be create a method within a method in java?

I don't believe it is possible, and anyways there really isn't any reason to do that. Just create a new method in the same class, or in a "utility" class


Can a main method in java be overloaded?

Yes. The main method is just like any other java method and can be overloaded. But - Only the method with public static void main(String[] args) signature will get invoked when the class is run.