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                      
info       Did you received any Funny E-Mails from your Friends and like to share with rest of our friends? Yeah!! you can post that stuff   HERE
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
how to call One constructor from another;
 Question Submitted By :: Neeraj_passion2001
I also faced this Question!!     Rank Answer Posted By  
 
  Re: how to call One constructor from another;
Answer
# 1
by using super keyword
 
Is This Answer Correct ?    17 Yes 2 No
Zorif
 
  Re: how to call One constructor from another;
Answer
# 2
Hi,

Using super you can invoke constructor which is in parent 
class. to invoke constructor which is in the same class we 
have to use this. for example:

public class Point {
    int m_x;
    int m_y;

    //============ Constructor
    public Point(int x, int y) {
        m_x = x;
        m_y = y;
    }

    //============ Parameterless default constructor
    public Point() {
        this(0, 0);  // Calls other constructor.
    }
    . . .
}
 
Is This Answer Correct ?    12 Yes 4 No
Ajay
 
 
 
  Re: how to call One constructor from another;
Answer
# 3
I think we find that anything you could have done in Java by
calling the default constructor from another constructor,
you can do easily in Curl by calling the default constructor
from a factory.
 
Is This Answer Correct ?    2 Yes 4 No
Talk2sreenivas@gmail.com
[Intac-india.com]
 
  Re: how to call One constructor from another;
Answer
# 4
. In one constructor, the first statement can be a call on
another constructor in the same class (use keyword this
instead of the class-name) or a call on a constructor of the
superclass (use keyword super instead of the class-name). In
a constructor for a subclass, the first statement must be
either this(…); or super(…); —if not, the call super(); is
automatically inserted for you.
 
Is This Answer Correct ?    6 Yes 0 No
Talk2sreenivas@gmail.com
[Intac-india.com]
 
  Re: how to call One constructor from another;
Answer
# 5
We can call the parent class constructor from the child 
class constructor.

class Parent
{
 int a;
 Parent(int x)
 {
  a=x;
 }
}
class Child extends Parent
{
 int b;
 Child(int x,int y)
 {
  super(x);
  b=y;
  System.out.println(a);
  System.out.println(b);
 }
}

class Test
{
public static void main(String args[])
{
 Child obj = new Child(1,2);	 
}
}
 
Is This Answer Correct ?    5 Yes 0 No
Tulasi Prasad
 
  Re: how to call One constructor from another;
Answer
# 6
This.constructername() keyword can be used with in the 
class to refer. To use super class constructer we need to 
give super.consturctername().
 
Is This Answer Correct ?    0 Yes 0 No
Sridhar
 
  Re: how to call One constructor from another;
Answer
# 7
constructor call from one class to another class by useing
the keyword super()(default),super(-)(parameter constructor)
 
Is This Answer Correct ?    0 Yes 0 No
Srinu
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
whays is mean by inner class? HCL3
what is unreachable code problem in multiple catch statements  2
What is the immediate parent class of the Applet class?  1
What is thread? BMC5
what is the difference between multitasking and multithreading?  8
Explain the relationship between the Canvas and Graphics class?  1
Why can't we make jsp as a controller and action servlet in struts? TCS7
What is Marker interface in java? and what is clone? Wipro7
What is Collection interface? Zensar1
what is the use of declaring constructor as private? Sai-Softech3
Explain Public static void main?  2
how many ways to create Thread and which one is good? runnable interface ot Thread class? Satyam3
what is meaning of JIT?  4
what is web.xml?and its use? CTS6
what is the difference between HashMap and Hashtable Value-Labs8
What is difference between static method and static variable?  6
33. try { 34. // some code here 35. } catch (NullPointerException e1) { 36. System.out.print(”a”); 37. } catch (RuntimeException e2) { 38. System.out.print(”b”); 39. } finally { 40. System.out.print(”c”); 41. } What is the result if a NullPointerException occurs on line 34? 1 c 2 a 3 ab 4 ac  2
what is an anonymous class? TCS5
what is the Use of throws exception?  2
What are the common problems you have faced while implementing Java?  1
 
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