Java Programming - Declarations and Access Control - Discussion
Discussion Forum : Declarations and Access Control - Pointing out the correct statements (Q.No. 5)
5.
class A
{
A( ) { }
}
class B extends A
{ }
Which statement is true?Answer: Option
Explanation:
Option B is correct. Class B inherits Class A's constructor which has no arguments.
Option A is wrong. Class B inherits Class A's constructor which uses default access.
Option C is wrong. There is just no implicit call to this( ).
Discussion:
11 comments Page 1 of 2.
Raja Mahesh Aravapalli said:
1 decade ago
I observed in SCJP 6 by kathy sierra and bert bates, that constructors will not be inherited from super class.
Could you please clarify ?
Could you please clarify ?
Aditya said:
1 decade ago
constructors are NOT inherited in subclass....
Ashok said:
1 decade ago
Then how the super class constructor will be executed when we create the object for sub class.
Rakesh said:
1 decade ago
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:
1 decade ago
class A
{
A( ) { }
}
class B extends A
{ }
Can any one tell me that B's constructor is public or not?
{
A( ) { }
}
class B extends A
{ }
Can any one tell me that B's constructor is public or not?
Inayath said:
1 decade ago
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.
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:
1 decade ago
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.
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:
1 decade ago
Can anyone please explain about initialization of a float object.
Dablu Gupta said:
1 decade ago
Can anyone please explain about initialization of a float object.
Meaning of these two lines:.
Float f1[ ], f2[ ];
F1 = new float[10];
Meaning of these two lines:.
Float f1[ ], f2[ ];
F1 = new float[10];
Nikhil said:
8 years ago
One constructor cannot inherit another constructor in any case.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers