Geeks Talk

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.

why i am getting an error while calling a constructor from another constructor

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 ...

Go Back   Geeks Talk > Software Development > Java
Register Blogs FAQ Tag Cloud Calendar Mark Forums Read

Java Java related Issues and Problems

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-28-2007
Junior Member
 
Join Date: Jun 2007
Posts: 10
Thanks: 0
Thanked 1 Time in 1 Post
raj_java_j2ee is on a distinguished road
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
Reply With Quote
The Following User Says Thank You to raj_java_j2ee For This Useful Post:
Sponsored Links
  #2 (permalink)  
Old 07-03-2007
Junior Member
 
Join Date: Jul 2007
Location: Bangalore
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
vijji_luck is on a distinguished road
Re: why i am getting an error while calling a constructor from another constructor

Hi,
You have to use "this" operator to call oe constructor from another.
Reply With Quote
  #3 (permalink)  
Old 07-11-2007
Junior Member
 
Join Date: Jul 2007
Location: Banglore
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
farheen is on a distinguished road
Smile Re: 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()
{
this(1,2);
}

public static void main(String args[]){
another_cons p=new another_cons();
System.out.println("x="+p.x+"y="+p.y);
}
}
Reply With Quote
  #4 (permalink)  
Old 07-22-2007
Junior Member
 
Join Date: Oct 2006
Location: India
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
garry99 is on a distinguished road
Smile Re: why i am getting an error while calling a constructor from another constructor

Quote:
Originally Posted by raj_java_j2ee View Post
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
Hi Farheen,
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
Reply With Quote
  #5 (permalink)  
Old 07-22-2007
Junior Member
 
Join Date: Oct 2006
Location: India
Posts: 4
Thanks: 2
Thanked 0 Times in 0 Posts
garry99 is on a distinguished road
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
Reply With Quote
Reply

  Geeks Talk > Software Development > Java

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


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


All times are GMT -4. The time now is 03:49 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.3.1
Copyright © 2009 GeekInterview.com. All Rights Reserved