|
|||||||
| Programming, Coding, (Web)Design Discuss all your programming or design needs with likeminded people. |
![]() |
|
|
Thread Tools |
|
|
#1 |
|
DivrerHaeven Seinor Mebmer
Join Date: Mar 2003
Location: Baltimore, MD
Posts: 236
Rep Power: 0 ![]() |
I was under the impression that it was possible to overload constructors in Java. Or maybe there is something wrong with my syntax? Can you help me out here guys and gals - whats wrong with this code?
------------------------------------------------- Code:
public class Ip_WOccur {
public char[] ip;
public int instances;
/** Creates a new instance of Ip_WOccur */
public Ip_WOccur( char[] init_ip, int init_instances ){
instances = init_instances;
ip = new char[init_ip.length];
for( int some_var=0 ; some_var<ip.length ; some_var++ ){
ip[some_var] = init_ip[some_var];
}
}
public Ip_WOccur( char[] init_ip ) {
this.Ip_WOccur(init_ip, 0);
}
}
Code:
[25:1] cannot resolve symbol
symbol : method Ip_WOccur (char[],int)
location: class Apache.Apache_Companion.Ip_WOccur
this.Ip_WOccur(init_ip, 0);
^
1 error
As you can probably tell, Java is new to me so I would greatly appreciate the efforts of anyone who can share their wisdom with me. P.S. - I am using Sun Java 1.4.2 VM
__________________
Pepole olny raed wrods. Btu oyu shuodl sitll check oyur spleling! http://realgar.hopto.org
|
|
|
|
|
|
#2 |
|
DriverHeaven Newbie
Join Date: May 2002
Location: Ireland
Posts: 16
Rep Power: 0 ![]() |
this thread is old , and you've probably since fixed it yourself, but dump the 'this.' in front of the 'Ip_WOccur(init_ip, 0);'
'this' is used to reference instance variables. Your instance variables should really also be private, no public. |
|
|
|
|
|
#3 |
|
A Legend in Underwear
Join Date: May 2002
Location: Unknown
Posts: 5,255
Rep Power: 0 ![]() |
Kinda odd.
this should reference the entire object, including it's private stuff. At least, thats the behaviour under C# and a few other langs - although I really don't know Java
__________________
Gentoo Linux - Developer (baselayout) Read my blog "I contend that we are both atheists. I just believe in one fewer god than you do. When you understand why you dismiss all the other possible gods, you will understand why I dismiss yours." Stephen Roberts |
|
|
|
|
|
#4 |
|
Back in London
Join Date: Jul 2003
Location: London
Posts: 1,797
Rep Power: 0 ![]()
|
java is very different to C++ and C but has the obvious things which are the same for nearly all programming languages. why are you doing java? cause simply put java is rubbish. avoide like the plague if you can use C or php
__________________
/|\ Asus P5W DH Deluxe, Intel C2D E6600, 2GB Corsair XMS2-6400C4 DDR2, E-VGA GeForce 7800 GT, Creative X-Fi Extreme Music, 500GB Seagate 7200.10 SATA, Lian Li PC-V1100 Aluminum Case Black, etc. http://germanjulian.com /|\ |
|
|
|
|
|
#5 | |
|
A Legend in Underwear
Join Date: May 2002
Location: Unknown
Posts: 5,255
Rep Power: 0 ![]() |
Quote:
I only know of one - java. So no, it's not rubbish
__________________
Gentoo Linux - Developer (baselayout) Read my blog "I contend that we are both atheists. I just believe in one fewer god than you do. When you understand why you dismiss all the other possible gods, you will understand why I dismiss yours." Stephen Roberts |
|
|
|
|
|
|
#6 |
|
DriverHeaven Newbie
Join Date: May 2002
Location: Ireland
Posts: 16
Rep Power: 0 ![]() |
I'd be with Uberlord on this one. Java can't be put down as rubbish. It's a 3.5Gl, C is 3, they both have their place. C turns to machinecode, Java to bytecode etc.
The guy is calling a constructor from a constructor, whereas he should have 2 proper constructers. 'this.' is also being used incorrectly here. It also looks like some of the processing is happening in the first constructor, which is also not advisable. The instance variables are public also, so proper OOP is out the window. I'm sure he's just learning and has since solved all of this. |
|
|
|
|
|
#7 |
|
Blues man
Join Date: Jul 2003
Location: In front of my computer
Posts: 35
Rep Power: 0 ![]() |
public Ip_WOccur( char[] init_ip ) {
this(init_ip, 0); <- this is the way it should be done } |
|
|
|
![]() |
| Thread Tools | |
|
|