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


Please Help Members By Posting Answers For Below Questions

Can we have a try block without catch block?

569


Do extraneous variables affect validity?

526


Explain java coding standards for methods?

606


How to create a fecelet view?

560


When a thread is executing a synchronized method , then is it possible for the same thread to access other synchronized methods of an object ?

611






What does exclamation mean in java?

573


What is the set interface in java programming?

627


Why java is called not pure object oriented language?

581


Can we compare two strings in java?

556


Can we define package statement after import statement in java?

558


How many arguments can be passed to main ()?

525


How do you do absolute value in java?

523


Do you know how to reverse string in java?

584


Given a singly linked list, determine whether it contains a loop or not without using temporary space?

582


Write a function to find out longest palindrome in a given string?

594