|
|
|
1000 Java Tips ebook
|
|
 

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java
programming articles and tips. Please take your copy here.
Take your copy of free "Java Technology Screensaver"!. |
|
Easy Learn Java: Programming Articles, Examples and Tips - Page 24
Previous
1060 Stories (530 Pages, 2 Per Page)
Next
Question: Why do not distinguish methods based on their return value?
|
Q: Why Java do not distinguish methods
based on their return value?
Only on class names and arguments list?
I think, it could be obvious from declaration:
void aa(){}
int aa(){}
to use it later in a such way:
int bbb = aa();
compiler could easily distinguish which function must be used here - int, not
void...
Answer: Yes, in this situation compiler
easily will find out which kind of function must be used.
But quite often a
method can be called directly - just to do something, not to return some value.
The return value is not important here:
...
aa();
...
In this case compiler can not find out which method must be used.
And other programmer reading your program will be confused as well.
197 bytes more | 41 comments | | Score: 0
|
Posted by jalex on Tuesday, February 25, 2003 (00:00:00) (4530 reads)
|
Question: Is it new Java feature that my class has no constructor?
|
Question: My Java class has no constructor!!!? Is it new Java feature, like generics?
I read that Java creates a
default constructor for every class if I do not do it myself -default one, without
arguments.
I wrote small program where I defined my constructor with two arguments. But in
another place I still need an empty constructor (without arguments).
And my compiler complains that it can not find it!
Answer: Java creates a default constructor
if you have no constructors at all.
If you create even one with arguments a
default constructor will not be created and it is your responsibility to add it
into a program.
25 comments | | Score: 3
|
Posted by jalex on Monday, February 24, 2003 (00:00:00) (5389 reads)
|
|
|