answersLogoWhite

Top Answer
User Avatar
Wiki User
Answered 2009-10-25 04:51:25

Yes they can. This is the fundamental feature of polymorphism and is called method overloading. Where you have multiple methods with the same name in a class. These methods differ from one another in the method signature alone.

001
๐Ÿ™
0
๐Ÿคจ
0
๐Ÿ˜ฎ
0
๐Ÿ˜‚
0
User Avatar

Your Answer

Related Questions


False. Two methods can have the same name in Java. It is called Method Overloading.


false. Two methods can have the same name in Java



The dictionary definition of polymorphism refers to a principle in biology in which an organism or species can have many different forms or stages. This principle can also be applied to object-oriented programming and languages like the Java language. Subclasses of a class can define their own unique behaviors and yet share some of the same functionality of the parent class.Overriding and Overloading are two techiques to achive polymorphism in Java.Method overloading: When a method in a class having the same method name with different arguments is said to be method overloading. Method overriding : When a method in a class having the same method name with same arguments is said to be method overriding.


No. There can be multiple java classes in the same .java file, but the name of the file must match the name of the public class in the file.


Method overloading is a technique in Java where you can have multiple methods in a class with the same name. These methods will have a different signature. Ex: public int add(int a, int b){} public float add(float a, float b){} The above two methods have the same name but a different signature. This is method overloading.


In Java there is a concept called Scope of a Variable. Which defines the places in the code where a variable can be accessed. When you declare a variable inside a method, that variable is available only inside that method. Outside the method you cannot access it. So if you declare another variable of the same name in another method, it is as good as declaring a variable afresh because the instances of those variables are specific to that method. Those two variables are not at all related.


That means you have two (or more) methods with the same name, but with different signatures - that is, the number or types of parameters are different. The compiler will automatically choose the correct method, according to the parameters provided.


That means that you have two or more methods with the same name, but with a different parameter list - either the number of parameters varies, or the type of at least one of the parameters.


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.


Oddly enough, there is a Java class named Class. It provides an easy way to tell if two unknown Objects are of the same type (through use of the Object.class method).


method header and method body There are two ways to call a method; the choice is based on whether the method returns a value or not.


No. Interfaces in Java are a construct to get polymorphism ( subtype polymorphism ) working in Java, but they are not a "kind" of polymorphism. In polymorphism happens when two objects respond to the same message ( method call ) in different way ( hence poly -> many, morphism -> way or shape : polymorphism -> many ways). In Java to be able to send the same message to two different objects you have to either inherit the same parent, or implement the same interface.



Both True and False Two methods can have the same name provided they have a different signature (Parameters, return type) If they have the same signature then two methods cannot have the same name.


Two methods can have the same name provided their signature is different.Ex:public int add(int a, int b){...}public int add(int a, int b, int c){...}This is allowed whereaspublic int add(int a, int b){...}public int add(int a, int b){...}This is not.The above only applies within a single Class or Interface definition.It is entirely possible for different classes to have a method of the exact same signature (i.e. return value, method name, argument list). If a subclass has a method with the same signature as a parent class, then that method is said to have overridden the parent class's method. There is no specific name for the case where two unrelated classes have the same method signature, though that case is perfectly legal. Different signatures with the same method name are also allowed (which is called overloading when a subclass does it).Interfaces follow the same rules and conventions as Classes in this matter.-------------------Two or more methods or constructor can have the same name provided they have different signature. In other words, when we can one of those methods, we should be able to tell which method was called even when they have the same name. You can read more about overloading constructors and methods on this page: http://www.javawithus.com/tutorial/overloading-constructors-and-methods


The notify() method is used in Thread Communication between two threads along with the wait() method


No. Each thread can have only one run method. You can overload the run method because it is just another java method but only the default run method with void return type will get called when you start the thread


Java doesn't have a printf method. To provide the implementation of printf method of C in java, the java has two print methods. They are1. print()2. println()The first method prints the text in braces on the same line, while the second is used to print on the next line. In fact, ln in println() stands for next line. We need not use /n while working in java.Actually, the System.out.format() function is practically identical to printf in C. When translating code from C to Java, you can generally replace all calls to printf(args...) with calls to System.out.format(args...)....and to answer the original question, Java's System.out.format() method is based off of C's printf() function.


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


Two methods can have the same name provided their method signatures are different. For ex: public int add(int a, int b, int c){ } public float add(float a, float b, float c){ } These two methods can co-exist in the same class in spite of having the same method names because their signatures are different. But public int add(int a, int b, int c){ } public int add(int a, int b, int c){ } You cannot have this. Because it is just a replica of the earlier method and it would cause duplication.


Just write two methods with the same name, but different types of parameters.Just write two methods with the same name, but different types of parameters.Just write two methods with the same name, but different types of parameters.Just write two methods with the same name, but different types of parameters.


Core JAVA and Advanced JAVA are the two types of JAVA


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; } }


A Method in Java is a piece of code that is designed to perform a specific operation. It takes in input arguments processes them and then returns a value. Ex: public int sum(int a, int b) { return a + b; } The above method takes two integer arguments and returns the sum of the two numbers passed.



Copyright ยฉ 2021 Multiply Media, LLC. All Rights Reserved. The material on this site can not be reproduced, distributed, transmitted, cached or otherwise used, except with prior written permission of Multiply.