I'm having a little trouble overloading methods in C#. I have two methods that look like this.
public static void Sample(string string1, string string2, string string3,
System.Windows.Forms.MessageBoxButtons buttons)
{}
public static void Sample(string string1, string[] string2, string string3, System.Windows.Forms.MessageBoxButtons b...
I have created a class named Times and I have to construct 4 overloaded methods. I just would like some help understanding overloaded methods and at least maybe some help with the first one. I would really appreciate it. Thanks :)
multiply 2 integers and return the (integer) product
multiply 3 integers and return the (integer) product
...
This question is hard to phrase, so I'm going to have to use some code samples. Basically, I have an (overloaded) method that takes 3 parameters, the last of which I overloaded. As in, sometimes the last parameter is a String, sometimes it's a double, etc. I want to call this method using a ternary conditional expression as the last para...
I don't see anything that I am doing wrong, but NetBeans gives me the following error:
incomparable types
required: boolean
found: java.lang.Object
public int compareTo(Object obj) {
if( obj instaceof Employee){
Employee employee = (Employee) obj;
if(this.weekly_earnings > employee.weekly_earnings)
return...
I'm making a shopping cart app in Google App Engine. I have many classes that derive from a base handler:
class BaseHandler(webapp.RequestHandler):
def get(self, CSIN=None):
self.body(CSIN)
Does this mean that the body() method of every descendant class needs to have the same argument? This is cumbersome. Only one descenda...
Given that Date has a method called "after(Date)" and Timestamp has a method the overrides it called "after(Timestamp)", why is the after method in Date called in the following code?
The question as to the unexpected results was asked here.
java.sql.Timestamp one = new java.sql.Timestamp(1266873627200L);
java.sql.Timestamp two ...
In C# you can do this:
foo = string.Format("{0} {1} {2} {3} ...", "aa", "bb", "cc" ...);
This method Format() accepts infinite parameters, being the first one how the string should be formatted and the rest are values to be put in the string.
Today I've come to a situation where I had to get a set of strings and test them, then I r...
I have a Java method that takes 3 parameters, and I'd like it to also have a 4th "optional" parameter. I know that Java doesn't support optional parameters directly, so I coded in a 4th parameter and when I don't want to pass it I pass null. (And then the method checks for null before using it.) I know this is kind of clunky... but the o...
We always say that method overloading is static polymorphism and overriding is runtime polymorphism. What exactly do we mean by static here? Is the call to a method resolved on compiling the code? So whats the difference between normal method call and calling a final method? Which one is linked at compile time?
...
Why does Jorge Ortiz advise to avoid method overloading?
...
Hello all,
I have one doubt concerning c# method overloading and call resolution.
Let's suppose I have the following C# code:
enum MyEnum { Value1, Value2 }
public void test() {
method(0); // this calls method(MyEnum)
method(1); // this calls method(object)
}
public void method(object o) {
}
public void method(MyEnum e) {
...
I have an overloaded action in my Controller:
public ActionResult AssignList(int id)
{
...
}
[AcceptVerbs((HttpVerbs.Get))]
public ActionResult AssignList(int id, bool altList)
{
...
}
I'd like to use the same partial view for both lists but it will potentially have a differently filtered l...
How can i decide the order in which my overloaded methods are displayed in visual studio, in the intellisense
...
Given I have a class with two constructors:
public class TestClass {
ObjectOne o1;
ObjectTwo o2;
public TestClass(ObjectOne o1) {
// ..
}
public TestClass(ObjectTwo o2) {
// ..
}
}
Please assume, that ObjectOne is an interface type, and ObjectTwo implements ObjectOne. What happens, if I call:
...
I have two overloaded methods, one with an optional parameter.
void foo(string a) { }
void foo(string a, int b = 0) { }
now I call:
foo("abc");
interestingly the first overload is called.
why not the second overload with optional value set to zero?
To be honest, I would have expect the compiler to bring an error, at least ...
For this example Java class:
package foo;
public class TestInterop
{ public String test(int i)
{ return "Test(int)"; }
public String test(Object i)
{ return "Test(Object)"; }
}
When I start Clojure and try to call the test(int) method, the test(Object) method is called instead, because Clojure automatically boxes the in...
I know this is not possible but can anyone provide a theory as to why Java chose not to support this? I am asking because I just ran into a situation where I think it would be nice to have.
...
I have the following situation: I need to sort trees based by height, so I made the Tree's comparable using the height attribute. However, I was also told to overwrite the equals and hashCode methods to avoid unpredictable behaviour.
Still, sometimes I may want to compare the references of the roots or something along those lines using ...
Can anybody explain in detail the reason the overloaded method print(Parent parent) is invoked when working with Child instance in my test piece of code?
Any pecularities of virtual methods or methods overloading/resolution in Java involved here?
Any direct reference to Java Lang Spec?
Which term describes this behaviour?
Thanks a lot.
...
In method overloading, is it possible to have different return types for a overloaded method?
for example,
void foo(int x) ;
int foo(int x,int y);
double foo(String str);
in general object oriented programming, is it possible?
...