File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes error in my code? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "error in my code?" Watch "error in my code?" New topic
Author

error in my code?

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
class Emp
{
private String name;
Emp(String str)
{
name = str ;
}
Emp()
{
this("hi"); //Why this code is not executing?
}
}
class Mgr
{
Emp e1 = new Emp();
Emp e2 = new Emp();
Mgr()
{
System.out.println("print");
}
}
class StaticEmp1
{
public static void main(String arr[])
{
Mgr m1 = new Mgr();
}
}
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
It is executing. What makes you think it isn't?
Try putting a print statement in the code you think isn't executing, to see what's happening.
[This message has been edited by Jim Yingst (edited March 17, 2000).]


"I'm not back." - Bill Harding, Twister
Manju Swamy
Greenhorn

Joined: Mar 03, 2000
Posts: 14

Could you please state you question clearly.

  • Did you had error while compiling? It compiles perfectly fine for me.
  • Are you expecting the this("hi") to print hi in the constructor? You need to refresh your constructor chaining concepts.
  • Do you have all these classes in one single source file?


  • In case you have all these classes are in one single file like Emp.java or Mgr.java, when try to compile and run from the IDE, since main() method is not defined in Mgr or Emp classes you will get a runtime error.
    In case you have successfully compiled the classes then try running StaticEmp1 class from the command prompt.



    [This message has been edited by Manju Swamy (edited March 17, 2000).]


Mind is like a parachute. It works only when it is open.
 
jQuery in Action, 2nd edition
 
subject: error in my code?
 
Similar Threads
Derived Property issue in Hibernate
comparable program counstructor not found exception
Sorting data list
please check this code
sorting table columns