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 unicode full form?
why an outer class cannot be declared as private?
What does the ‘static’ keyword mean? Is it possible to override private or static method in java?
What is string substring?
What is :: operator in java?
How to find the index of the largest number in an arraylist java?
Does .length start 0 java?
Is math an abstract class in java?
What is the main use of java?
what is mutual exclusion? : Java thread
You can create a string object as string str = “abc”; why cant a button object be created as button bt = “abc”;? Explain
What is double parsedouble in java?
What are the ways to instantiate the class class?
What is the basic difference between string and stringbuffer object?
What is meant by final class?