answersLogoWhite

0


Best Answer

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;

}

}

User Avatar

Wiki User

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

Wiki User

13y ago

false. Two methods can have the same name in Java

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: The methods cannot have the same name in java true or false?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

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 explanation for the different access modifiers in Java?

An Access Modifier is a key word in java that determines what level of access or visibility a particular java variable/method or class has. There are 4 basic access modifiers in java. They are:PublicProtectedUnspecified (package-private)PrivateClasses can only be declared public or left unspecified (the "package-private" default level). Methods can be declared any of the above.See the Link on the Java Tutorial for a very good explanation of the various levels of access each modifier provides.


Explain the term identifier in java?

Identifiers are the strings you use in Java source code to identify unique things, such as variables, classes, and methods. Identifiers may be any word beginning with a letter or underscore, and continuing with letters, numbers, and underscores. Identifiers are case sensitive.


What is compile time polymorphism in java?

Compile Time Polymorphism in Java is when you have the several methods with same name and different parameters and compiler has to decide how to select which method has to run based on the arguments hence the name Compile time polymorphism or method overloading.


What is the first name before of the Java Programming?

The first name of the Java Programming was Oak. It then went by the game Green and finally Java from Java coffee.

Related questions

The name of a Java program file must match the name of the class with the extension java A True B False?

True


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 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 explanation for the different access modifiers in Java?

An Access Modifier is a key word in java that determines what level of access or visibility a particular java variable/method or class has. There are 4 basic access modifiers in java. They are:PublicProtectedUnspecified (package-private)PrivateClasses can only be declared public or left unspecified (the "package-private" default level). Methods can be declared any of the above.See the Link on the Java Tutorial for a very good explanation of the various levels of access each modifier provides.


Is it possible to define two methods that have the same name but different parameters?

Yes. It is called Method Overloading in Java


Explain the term identifier in java?

Identifiers are the strings you use in Java source code to identify unique things, such as variables, classes, and methods. Identifiers may be any word beginning with a letter or underscore, and continuing with letters, numbers, and underscores. Identifiers are case sensitive.


Java program file must match the name of class with extension true or false?

The name of the .java file should exactly match with the name of the public class in the file. Ex: public class Test { ..... } this file should be saved as Test.java


What is the difference between method and function in java?

A function is a piece of code that can be reused by calling its name while a method is a function that is associated with a class. In Java, functions are usually referred to as static methods.


What is compile time polymorphism in java?

Compile Time Polymorphism in Java is when you have the several methods with same name and different parameters and compiler has to decide how to select which method has to run based on the arguments hence the name Compile time polymorphism or method overloading.


What is the first name before of the Java Program?

The first name of the Java Programming was Oak. It then went by the game Green and finally Java from Java coffee.


What is the first name before of the Java Programming?

The first name of the Java Programming was Oak. It then went by the game Green and finally Java from Java coffee.


Is it possible to have file name as java eg javajava?

Yes you can name a file (class if you use eclipse) java or even have java in the name.