Java Programming - Declarations and Access Control - Discussion

Raja Mahesh Aravapalli said: (Feb 13, 2012)  
I observed in SCJP 6 by kathy sierra and bert bates, that constructors will not be inherited from super class.

Could you please clarify ?

Aditya said: (Mar 11, 2012)  
constructors are NOT inherited in subclass....

Ashok said: (Jul 24, 2012)  
Then how the super class constructor will be executed when we create the object for sub class.

Rakesh said: (Aug 31, 2012)  
There is implicit call to base class constructor from each derived class constructor . Using keyword super() it calls base class constructor . "super();" is first statement of every derived class constructor either we provide explicitly or it is provided by JVM implicitly.

Ejunika said: (Jul 7, 2013)  
class A
{
A( ) { }
}

class B extends A
{ }

Can any one tell me that B's constructor is public or not?

Inayath said: (Aug 14, 2013)  
If we are not providing any constructor compiler will place a default(no arg constructor) and call to it's super class constructor.

Compiler provide following code for B class as follows.

class B extends A{
B(){
super();
}
}

So constructors are not inherited although they are chained.

Syed Shahzad said: (Apr 16, 2015)  
public class A {
A() {
System.out.println("A");
}
}

public class B extends A{

}

1. Class B if in the same package as of A.

2. Class B constructor default access is public.

3. Class B constructor will make call class A default constructor, here class A has explicit constructor declared with default access so it will be executed as a first thing in constructor B.

4. According to me option is correct at all.

Dablu Gupta said: (Jul 26, 2015)  
Can anyone please explain about initialization of a float object.

Dablu Gupta said: (Jul 26, 2015)  
Can anyone please explain about initialization of a float object.

Meaning of these two lines:.

Float f1[ ], f2[ ];

F1 = new float[10];

Nikhil said: (Aug 24, 2017)  
One constructor cannot inherit another constructor in any case.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.