Results 1 to 4 of 4
  1. #1
    preety is offline Member
    Join Date
    Apr 2013
    Posts
    2
    Rep Power
    0

    Default constructor inheritence

    if constructor is not inherited then what this example shows?


    public class app1 {

    public static void main(String a[])
    {
    sub b=new sub();
    }


    }
    class add
    {
    int q;
    add()
    {
    q=7;
    System.out.print("hiiii");
    }
    }
    class sub extends add
    {
    sub()
    {
    System.out.print(q);
    }
    }
    Last edited by preety; 04-09-2013 at 11:22 AM.

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default Re: constructor inheritence

    What is what? Please post your code usind code tags. [code] your code here [/code]
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    335
    Rep Power
    4

    Default Re: constructor inheritence

    Hi preety, welcome.

    The short answer is "Not inheritance".

    The long answer is inheritance is the ability to use variables and methods defined in a superclass. The constructor of the superclass is not inherited by the subclass but is called by the constructor of the subclass upon the object's creation.
    You can call the constructor of the superclass explicidly from the sub by calling the method super(). If no call is made then the constructor calls the default constructor of the superclass.
    Inheritance

    Regards.

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,527
    Blog Entries
    7
    Rep Power
    20

    Default Re: constructor inheritence

    Why did you abandon your previous thread? constructor inheritence and started this identical thread?

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. constructor inheritence
    By preety in forum New To Java
    Replies: 1
    Last Post: 04-06-2013, 11:37 AM
  2. Basic inheritence question
    By jubbiejub in forum New To Java
    Replies: 8
    Last Post: 03-17-2012, 04:35 AM
  3. Inheritence
    By UJJAL DHAR in forum New To Java
    Replies: 0
    Last Post: 12-04-2010, 09:11 AM
  4. inheritence questions
    By mac in forum New To Java
    Replies: 1
    Last Post: 04-05-2010, 10:54 PM
  5. Getting around inheritence
    By nick2price in forum New To Java
    Replies: 3
    Last Post: 01-18-2009, 06:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •