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 a numeric digit?
Can you make a constructor final in Java?
What is the difference between a loader and a compiler?
what is meant by encapsulation?
What is Garbage Collection in Java
Write a program to show whether a graph is a tree or not using adjacency matrix.
Can I extend singleton class in java?
Can a class have multiple superclasses?
What is method overloading and method overriding?
What does int [] mean in java?
What is java used for on a computer?
Can an anonymous class be declared as implementing an interface and extending a class in java programming?
What is a line break?
What is string example?
What is generics in java interview questions?