File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "error in my code?" Watch "error in my code?" New topic

error in my code?

Ranch Hand

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

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

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 or, 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.
I agree. Here's the link:
subject: error in my code?
It's not a secret anymore!