Prepare for your Next Interview
|
Welcome to the Geeks Talk forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
This is a discussion on why i am getting an error while calling a constructor from another constructor within the Java forums, part of the Software Development category; class another_cons { int x,y; another_cons(int a,int b) { x=a; y=b; } another_cons() { another_cons(1,2); } public static void main(String args[]) { another_cons p=new another_cons(); System.out.println("x="+p.x+"y="+p.y); } } C:\forte_jdk\j2sdk1.4.0\bin>javac another_cons.java ...
|
|||||||
|
|||
|
why i am getting an error while calling a constructor from another constructor
class another_cons
{ int x,y; another_cons(int a,int b) { x=a; y=b; } another_cons() { another_cons(1,2); } public static void main(String args[]) { another_cons p=new another_cons(); System.out.println("x="+p.x+"y="+p.y); } } C:\forte_jdk\j2sdk1.4.0\bin>javac another_cons.java another_cons.java:11: cannot resolve symbol symbol : method another_cons (int,int) location: class another_cons another_cons(1,2); ^ 1 error friends can any one explain while i am getting this error |
| The Following User Says Thank You to raj_java_j2ee For This Useful Post: | ||
| Sponsored Links |
|
|||
|
class another_cons
{ int x,y; another_cons(int a,int b) { x=a; y=b; } another_cons() { this(1,2); } public static void main(String args[]){ another_cons p=new another_cons(); System.out.println("x="+p.x+"y="+p.y); } } |
|
|||
|
Quote:
You have made a small mistake in this program,the error which is coming up is because of athe name of the class and constructor used in small letters,you should have used Another_cons instead of another_cons,ur program will run smoothly if u will use Another_cons and save ur file with this name only.I have tried to run this program and it has run successfully.Ther is one more thing to be noticed thatg constructor has no return type.It should have the void keyword.The code mentioned below will definately run and help u. class Another_cons { int x,y; public void Another_cons(int a,int b) { x=a; y=b; } Another_cons() { Another_cons(1,2); } public static void main(String args[]) { Another_cons p=new Another_cons(); System.out.println("x="+p.x+"y="+p.y); } } Thanx & Regards Gaurav Bhasin |
|
|||
|
Re: why i am getting an error while calling a constructor from another constructor
"=="
checks for the object in the memory location,whether both the string are pointing to the same memory location or another. whereas "equals" check for similarity or equality between two strings |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Which constructor will be called in main | sandhyatammala | OOPS | 27 | 04-10-2009 11:28 PM |
| constructor | emb.mallik | C and C++ | 1 | 03-02-2009 04:50 PM |
| Constructor in place of init() method | Lokesh M | Java | 1 | 01-31-2008 03:43 PM |
| about static methods calling.... | psuresh1982 | Java | 3 | 05-11-2007 09:14 AM |
| Icon Constructor converts images of any format into Windows icons. | JobHelper | Geeks Lounge | 0 | 02-27-2007 09:20 AM |