Hello can anyone answer this question for me.
Ive been looking over this block of code below.
They say that the class defines a method not a constructor since it has a return value. The method happens to have the same name as the class but that is irrelevant.
So i have one question.
1.)If the method happens to have the same name as the class and it is returning a value then this should result in a complation error. How can this not.
Thanks.
public class MyClass{
long var;
public void MyClass(long param){var = param;}
public static void main(String[] args){
MyClass a,b;
a = new MyClass();
b = new MyClass(5);
}
}
Ive been looking over this block of code below.
They say that the class defines a method not a constructor since it has a return value. The method happens to have the same name as the class but that is irrelevant.
So i have one question.
1.)If the method happens to have the same name as the class and it is returning a value then this should result in a complation error. How can this not.
Thanks.
public class MyClass{
long var;
public void MyClass(long param){var = param;}
public static void main(String[] args){
MyClass a,b;
a = new MyClass();
b = new MyClass(5);
}
}