Java J2ee interview questions and answers: – From the below java code which constructor will fire first?

You can see our Java J2ee interview question videos from http://www.questpond.com/java/javaj2eedesignpattern.html

Ok, the first thing, let’s try to understand the above java interview question.  Let’s say you have two classes one is parent class and the other is a child class which extends (inherits) from the parent class as shown in the below code. Now if you create the object of “Child” class which constructor will fire first.

 class Parent

{

public Parent()

{

System.out.println(“This is parent”);

}

}

class Child extends Parent

{

public Child()

{

System.out.println(“This is Child”);

}

}

The answer is first the Parent class constructor will get executed and then the child class constructor will fire.

One more  Java j2ee interview question which was recently asked  to one of my friend was :-  Does Stringbuffer always give better performance as compared to string.

See the following video on By using String or String Buffer performance increases:-