how to call One constructor from another;
Answer Posted / 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 |
Post New Answer View All Answers
What is synchronization and why is it important in java programming?
What are the different http methods?
What is the difference between Java and C++?
What is static import in java?
which pattern is default in scanner package?
How do you declare a destructor in java?
How does list work in java?
What is a class instance variable?
Define locale.
What is the benefit of using enum to declare a constant?
Can a constructor be made final?
What is the difference between the paint() and repaint() methods?
How do I convert a string to an int in java?
Can a private method of a superclass be declared within a subclass?
What does the string method compareto () do?