ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   SiteMap shows list of All Categories in this site.
Google
 
Categories  >>  Software  >>  Core Java  >>  Java J2EE  >>  Java Related
 
 


 

 
 Core Java interview questions  Core Java Interview Questions
 Advanced Java interview questions  Advanced Java Interview Questions
 Swing interview questions  Swing Interview Questions
 EJB interview questions  EJB Interview Questions
 Servlets interview questions  Servlets Interview Questions
 Struts interview questions  Struts Interview Questions
 JDBC interview questions  JDBC Interview Questions
 JMS interview questions  JMS Interview Questions
 SunOne interview questions  SunOne Interview Questions
 J2EE interview questions  J2EE Interview Questions
 Weblogic interview questions  Weblogic Interview Questions
 Websphere interview questions  Websphere Interview Questions
 Java Networking interview questions  Java Networking Interview Questions
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions
Question
Can a class inherit the constructors of its superclass?
 Question Submitted By :: Nimitha
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Can a class inherit the constructors of its superclass?
Answer
# 1
No a subclass cannot inherit the constructors of its
superclass. Constructors are special function members of a
class in that they are not inherited by the subclass.
 
Is This Answer Correct ?    4 Yes 1 No
Ranganathkini
 
  Re: Can a class inherit the constructors of its superclass?
Answer
# 2
Hi... No.constructor cannot be inherited from super class.
 
Is This Answer Correct ?    4 Yes 0 No
Devarathnam
 
 
 
  Re: Can a class inherit the constructors of its superclass?
Answer
# 3
In the overriding concepts subclass can inherit or get the 
parentclass constructor using the super keyword
 
Is This Answer Correct ?    2 Yes 4 No
Kamala
 
  Re: Can a class inherit the constructors of its superclass?
Answer
# 4
No constructor overriding is not possible only constructor
overloading is possible
 
Is This Answer Correct ?    3 Yes 0 No
Ravikiran(aptech Mumbai)
 
  Re: Can a class inherit the constructors of its superclass?
Answer
# 5
No, a class can not inherit the constructor of its 
superclass. This subclass can inherit the instance 
variables and tha methods of the super class. 
Using 'super' keyword a sub class can inherit the 
constructors. This is only the solution.
 
Is This Answer Correct ?    0 Yes 3 No
Shaziya Parveen
 
  Re: Can a class inherit the constructors of its superclass?
Answer
# 6
Inheriting will inherits the constructor as well.

// This program uses inheritance to extend Box.
class Box {
double width;
double height;
double depth;
// construct clone of an object
Box(Box ob) { // pass object to constructor
width = ob.width;
height = ob.height;
depth = ob.depth;
}
// constructor used when all dimensions specified
Box(double w, double h, double d) {
width = w;
height = h;
depth = d;
}
// constructor used when no dimensions specified
Box() {
width = -1; // use -1 to indicate
height = -1; // an uninitialized
depth = -1; // box
}
// constructor used when cube is created
Box(double len) {
width = height = depth = len;
}
// compute and return volume
double volume() {
return width * height * depth;
}
}
// Here, Box is extended to include weight.
class BoxWeight extends Box {
double weight; // weight of box
// constructor for BoxWeight
BoxWeight(double w, double h, double d, double m) {
width = w;
height = h;
depth = d;
weight = m;
}
}
class DemoBoxWeight {
public static void main(String args[]) {
BoxWeight mybox1 = new BoxWeight(10, 20, 15, 34.3);
BoxWeight mybox2 = new BoxWeight(2, 3, 4, 0.076);
double vol;
vol = mybox1.volume();
System.out.println("Volume of mybox1 is " + vol);
System.out.println("Weight of mybox1 is " + mybox1.weight);
System.out.println();
vol = mybox2.volume();
System.out.println("Volume of mybox2 is " + vol);
System.out.println("Weight of mybox2 is " + mybox2.weight);
}
}

The output from this program is shown here:
Volume of mybox1 is 3000.0
Weight of mybox1 is 34.3
Volume of mybox2 is 24.0
Weight of mybox2 is 0.076

BoxWeight inherits all of the characteristics of Box and 
adds to them the weight
component. It is not necessary for BoxWeight to re-create 
all of the features found in
Box. It can simply extend Box to meet its own purposes
 
Is This Answer Correct ?    1 Yes 0 No
Sridhar
 
  Re: Can a class inherit the constructors of its superclass?
Answer
# 7
No, We cant inherit the constructor. Using super we can call
the constructor but we cannot modify the working of it.
 
Is This Answer Correct ?    0 Yes 0 No
Patil Abhijeet
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
what modifiers are used with top-level class?  2
What is the smallest package in Java API?  4
can we declare private class in java file?  6
Can a class inherit the constructors of its superclass? Wipro7
what is a thread? IBM10
what is main purpose of interface? Accenture2
can we have function for truncating the sign as like abs in oracle.  1
whats string ? HCL8
Can we access private data outside of the class directly in java programming language? Why There is no runtime checking in java, which leads to access the private data directly outside of a class? Google2
Can a lock be acquired on a class?  2
os is developed in c no java is more secured then c na why dont the os developed is developed using java  1
Why all programming languages have main as a execution starting point?  2
whst is encapsulation?when u encpsulate actually while devoloping code? AMDOC5
which one the better thread emplemented thread or extended ? Fidelity3
why the equals method can be override?when we override the equals method?  4
Why cant we define System.out.println() inside a class directly?  4
how can i connect to database in a applet ?  1
What are inner and anonymous class?  2
what are the jsp tags with example? Photon1
What is adapter class?  2
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com