answersLogoWhite

0


Best Answer

Two methods can have the same signature when you override a method. A superclass calledrectangle might have a method called draw(). Then you make a subclass called squareand give it a method called draw() also. When you call the draw() method from square, it overrides the draw() method in rectangle. Note this is different than overloading, where you have two methods with the same name but different signatures, like draw() and draw(Color c).

User Avatar

Wiki User

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

Wiki User

13y ago

No. Overloaded methods have the same name, but different signatures.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

Yes. Overridden methods have the same signature whereas Overloaded methods have a different signature

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How can two methods have the same signature?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Is it possible to have a method in the super class and sub class with same name but different signature?

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.


The methods cannot have the same name in java true or false?

False. Methods in a class can have the same name as long as they have a different signature. You cannot duplicate method code inside a class but you can always have methods that have the same name but a different signature. Ex: Here I have created two methods in a class that have the same name "sum" but have a different argument types, and return types and hence perfectly allowable in a java class. Public class PolymorphismExample { public int sum(int a, int b){ return a + b; } public double sum (double a, double b){ return a + b; } }


Two methods cannot have the same name in Java A True B False?

Multiple methods with the same name is called method overloading. The way to do this is to have the different methods accept different parameters. Examples: Adding two values and returning the result. Let's use different methods for adding various numeric primitives. public static int add(int a, int b) { return a + b; } public static short add(short a, short b) { return a + b; } public static long add(long a, long b) { return a + b; } public static float add(float a, float b) { return a + b; } public static double add(double a, double b) { return a + b; }


What is function overloading in java?

Any function or method in Java that is coded by the programmer is called a user defined method in Java. The JAVA API (Application Programming Interface) has a set of predefined classes & methods that are for our usage. Whatever methods we create apart from these are termed as user defined methods. In java we not use the term functions. We call them "Methods"


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"

Related questions

Is it possible to have a method in the super class and sub class with same name but different signature?

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.


The methods cannot have the same name in java true or false?

False. Methods in a class can have the same name as long as they have a different signature. You cannot duplicate method code inside a class but you can always have methods that have the same name but a different signature. Ex: Here I have created two methods in a class that have the same name "sum" but have a different argument types, and return types and hence perfectly allowable in a java class. Public class PolymorphismExample { public int sum(int a, int b){ return a + b; } public double sum (double a, double b){ return a + b; } }


What is a signature in Java?

A signature is a term that we can use to identify a method. A method signature is something that helps us specifically identify a method. The components of a methods signature are: 1. Its access modifier 2. Return type 3. Parameters Ex: public void getName(int empnum){} public String getName(int empnum, int age){} The above two methods are of the same name but they have a different signature.


What key signature has two B flats?

No key signature has two of the same flat or sharp.


Two methods cannot have the same name in Java A True B False?

Multiple methods with the same name is called method overloading. The way to do this is to have the different methods accept different parameters. Examples: Adding two values and returning the result. Let's use different methods for adding various numeric primitives. public static int add(int a, int b) { return a + b; } public static short add(short a, short b) { return a + b; } public static long add(long a, long b) { return a + b; } public static float add(float a, float b) { return a + b; } public static double add(double a, double b) { return a + b; }


What is function overloading in java?

Any function or method in Java that is coded by the programmer is called a user defined method in Java. The JAVA API (Application Programming Interface) has a set of predefined classes & methods that are for our usage. Whatever methods we create apart from these are termed as user defined methods. In java we not use the term functions. We call them "Methods"


What is the key signature for g minor on piano?

Two flats, the same as Bb Major.


How do you overload static methods in java?

Just create two methods with the same name, but with different types or numbers of parameters.


What if the two people who have to sign something to be notarized do not live in the same place?

The first signs it and has his/her signature notarized, sends it to the second, and the second person signs it and has his/her signature notarized.


What two methods are used to determine the age of a rock?

The two methods are relative dating and radioactive dating for fossils. I think it's the same for rocks.


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"


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.