aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes flow of execution Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "flow of execution" Watch "flow of execution" New topic
Author

flow of execution

Neha Sawant
Ranch Hand

Joined: Oct 11, 2001
Posts: 204
hi
1) how is the flow of execution of a program.
static variable-->static intializer-->instance variable-->instance initializer-->constructor of superclass-->constructor of subclass
Am i right.
2) when a no arg constructor of subclass is called then which constructor of superclass is called.
Is it only the no arg constructor or also the matching constructor in superclass is called or no constructor from super class is called.

nss
Fei Ng
Ranch Hand

Joined: Aug 26, 2000
Posts: 1241
1) how is the flow of execution of a program.
static variable-->static intializer-->instance variable-->instance initializer-->constructor of superclass-->constructor of subclass
Am i right.

a note, Depends on whichever come first too.

2) when a no arg constructor of subclass is called then which constructor of superclass is called.
Is it only the no arg constructor or also the matching constructor in superclass is called or no constructor from super class is called.[/B]
if u didn't put super(....) it is the no arg constructor
of super class. If no super(...) and this(...) complier will put super() for you.
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120

"instance variable-->instance initializer-->constructor of superclass"
it's the other way round, remember the superclass instances should be initialized before subclasses instances.
hope helps

SCJP2. Please Indent your code using UBB Code
Neha Sawant
Ranch Hand

Joined: Oct 11, 2001
Posts: 204

class Superclass
{
Superclass()
{System.out.println("1");
}
Superclass(int a)
{S.o.p("2");
}
}
class Subclass extends Superclass{
Subclass()
{S.o.p("3");
}
Subclass(int b)
{S.o.p("4");
}
public static void main(String args[])
{
Subclass s= new Subclass(5);}
}
what will the output be?
Will it be 4
Adrian Muscalu
Ranch Hand

Joined: May 08, 2000
Posts: 73
In my oppinion, the output will be 1 and 4. The constructor in the subclass will call the "no-parameter" constructor from the superclass and then it will take care of himself.
Correct me if I'm wrong.


SCJP2, SCWCD
Neha Sawant
Ranch Hand

Joined: Oct 11, 2001
Posts: 204
Got it
but just to confirm once again the constructor of the subclass will not call its no arg costructor but only the no args constructor of super class and if the superclass has no args constructor then will print only 4.
correct me if i am wrong
thanx in advance
neha
 
I agree. Here's the link: jrebel
 
subject: flow of execution
 
Similar Threads
Initialization sequence
initialization order
about how an instance is created
about static and instance initializer blocks with inheritance
Inheritance and Subclasses