how to call One constructor from another;

Answers were Sorted based on User's Feedback



how to call One constructor from another;..

Answer / zorif

by using super keyword

Is This Answer Correct ?    22 Yes 3 No

how to call One constructor from another;..

Answer / ajay

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 ?    21 Yes 5 No

how to call One constructor from another;..

Answer / tulasi prasad

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 ?    13 Yes 1 No

how to call One constructor from another;..

Answer / talk2sreenivas@gmail.com

. 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 ?    9 Yes 2 No

how to call One constructor from another;..

Answer / shweta chaubey

with the use of super(); method

Is This Answer Correct ?    1 Yes 0 No

how to call One constructor from another;..

Answer / sridhar

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 ?    1 Yes 1 No

how to call One constructor from another;..

Answer / srinu

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

how to call One constructor from another;..

Answer / gokul d

just by initializing the class(constructor) in the another
class where it has to be invoked.for eg
class a{
a()
{
}
}
class b
{
b()
{
new a();
}
}

Is This Answer Correct ?    1 Yes 2 No

how to call One constructor from another;..

Answer / muthu mariyan.imu

we can call super class constructor if it is no argument constructor.a sub class inherit only default and no argument constructor

Is This Answer Correct ?    0 Yes 1 No

how to call One constructor from another;..

Answer / talk2sreenivas@gmail.com

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 ?    5 Yes 9 No

Post New Answer

More Core Java Interview Questions

How can we get one Interface methods whit out using implementation of interface

1 Answers   Oracle,


What are the advantages and disadvantages of reference counting in garbage collection?

0 Answers  


What is the difference between static and global variables and also define what are volatile variables?

0 Answers   Flextronics, Hexaware,


How to invoke external process in java.

0 Answers  


What is a lock or purpose of locks in java?

0 Answers  


what is for datainputstream?

1 Answers  


What is OOPs & Why?

3 Answers  


What modifiers may be used with a top-level class?

0 Answers  


What is the purpose of tostring() method in java?

0 Answers  


What is meant by flickering?

0 Answers  


How can you set the applet size?

0 Answers  


What is the use of collections in java? How it is implemented in real time applications?

2 Answers  


Categories