The constructor should be called just for the first object only.

hello everybody!
Please check out this code:
class father
     father()
class son1 extends father
     son1()
class son2 extends father
     son2()
public check
    public static void main( String args[] )
     son1 object1=new son1();
     son2 object2=new son2();
In both the case for
son1 object1=new son1();*
son2 object2=new son2();*
the constructor of the father class is invoked, i.e,
father()
+{+
+}+
What I want is the father constructor should be invoked only once i.e, when the first object(object1) is created and when the second object(object2) is created the father constructor should not be invoked. Is that possible in java, if yes, how?. Where should I make the changes in the given code?
Please advice,
Thank you.

No, not the way you have designed it.
What you have is
Son1 IS A Father
Son2 IS A Father
Are you sure that is what you want, while the Sons will most likely end up as Fathers, as you only want the Father constructor called once it sounds like you want a
Son1 HAS A Father.
To do this you need to user composite relation.
I.e.
class Father {
   Father() {
       System.out.println( "Daddy!" );
class Son {
  private final Father myFather;
   Father( Father myFather ) {
       this.myFather = myFather;
       System.out.println( "Son" );
public static void main( String[] args ) {
    Father baba = new Father();
    Son jerry = new Son( baba );
    Son fred = new Son( baba );
}

Similar Messages

  • Should i call apple for three broken ipods in a row?

    i got this ipod touch from best buy and it just stopped working, then i returned it to get a refurbished one and it had sound problems, and then i returned that one and the one i have now has a touch screen that doesnt work. it wont press certain letters and it doesnt slide to well. should i call apple for this?

    If within warranty (check using the link below) I would make an appointment at the Genius Bar of an Apple store or call AppleCare.  If not within warranty you may have to go back to Best Buy.
    https://selfsolve.apple.com/agreementWarrantyDynamic.do

  • How do I set the wallpaper for the the first page only

    how do I set the wallpaper for the the first page only.I have my ICE #'s as wallpaper but I only want it on the first page

    When you set a wallaper you are asked where you want to set it. Either Lock Screen or Home Screen or Both.
    If you choose Lock screen it will only appear when you wake up your phone.
    If you set it to Home screen, then it wil be set behind the app icons on all your home screens.
    If you choose both, then it will be on both.
    Not sure what you mean by the " have a photo of my ICE in contacts that I am trying to use????" 
    The Photo should be in the Photos App. how is it in contacts?  is it assigned to a contact?

  • Why is my ping so high in the first column only when i do a tracert?

    When i do a tracert my ping is really high in the first column only on each hop and then it drops to a respectable level. Does anyone know why it is like this on my 4G LTE device? On my dsl when i do the same ping test its pretty even across on each hop. This is what im seeing when i do a ping test on my 4G LTE device.
    tracert www.yahoo.com
    Tracing route to ds-any-fp3-real.wa1.b.yahoo.com [98.139.183.24]
    over a maximum of 30 hops:
      1     9 ms     3 ms     3 ms 
      2  1101 ms    34 ms    38 ms  193.sub-66-174-20.myvzw.com [66.174.20.193]
      3   169 ms    55 ms    52 ms  49.sub-69-83-13.myvzw.com [69.83.13.49]
      4    52 ms    56 ms    54 ms  194.sub-69-83-13.myvzw.com [69.83.13.194]
      5   179 ms    58 ms    57 ms  101.sub-66-174-17.myvzw.com [66.174.17.101]
      6   168 ms    57 ms    60 ms  TenGigE0-0-1-0.GW14.BOS4.ALTER.NET [152.179.2.97
      7   181 ms    58 ms    57 ms  0.ge-0-3-0.XL3.BOS4.ALTER.NET [152.63.17.130]
      8   170 ms    59 ms    58 ms  0.ae3.BR1.NYC1.ALTER.NET [152.63.18.222]
      9   177 ms    67 ms    59 ms  ae11.edge2.NewYork.Level3.net [4.68.62.41]
    10     *        *        *     Request timed out.
    11     *        *        *     Request timed out.
    12     *        *        *     Request timed out.
    13   192 ms    49 ms    60 ms  ae-4-90.edge4.NewYork1.Level3.net [4.69.155.210]
    14   185 ms    51 ms    60 ms  YAHOO-INC.edge4.NewYork1.Level3.net [4.28.130.82
    15   380 ms    73 ms   129 ms  ae-5.pat2.bfz.yahoo.com [216.115.96.67]
    16   339 ms    69 ms   146 ms  ae-4.msr2.bf1.yahoo.com [216.115.100.73]
    17   215 ms   152 ms    80 ms  xe-5-0-0.clr2-a-gdc.bf1.yahoo.com [98.139.128.11
    18   289 ms   217 ms   217 ms  et-17-1.fab6-1-gdc.bf1.yahoo.com [98.139.128.47]
    19   187 ms    87 ms    79 ms  po-14.bas2-7-prd.bf1.yahoo.com [98.139.129.227]
    20   474 ms   314 ms   294 ms  ir2.fp.vip.bf1.yahoo.com [98.139.183.24]
    Trace complete.

    hi there
    see you never got an answer from vzw
    take it you still have the high ping or no ping  in my cases
    your doing better then i
    seems the lte is getting bad with this problem over time as my connection times out causing half loaded web pages  and lots of buffering in video playback
    i have had 3 tickets in the past 3 month to try and get this fixed  but they say cant find anything wrong
    and noone else is having the problem here are a few things that seems to have helped me out
    1  increase your TTL  time till live 
    this tells your computer to wait a bit longer before giving up and requesting that a packet of info be resent
    2 in your computers network settings and reg you can change packet size to a smaller number and add a stop bit to the packet with a time stamp on each packet back in the old days  this was what v 90 modems did to get v92 speeds and did help with noisy copper wire dial up and seems to help here too
    http://www.dslreports.com/drtcp
    is a tool that will help you change your computer setting and reg
    use drtcp and the results from this page
    http://www.dslreports.com/tweaks
    xp win 7 win 8 this will help.  vista did it right and dynamically change these settings on the fly and all of step 2 is unnecessary
    remember your original settings write them down so you can go back to them should you have problems
    also make a restore point and backup your reg before tinkering with windows os
    send a private message to me if you need more help  or get a computer savvy friend to help you out if you need
    3  if your signal noise is under 4G  -100bd the lower the better,  there is a way to set your android to lte only  mode.
    more likely to lose data and voice in weak signal areas but great if tethering or hotspotting at home
    dail *#*#4636#*#* this is a back door to your android software and is open source code by android os  not vzw
    and will not unlock your phone voiding warranties. be warned though if you set things wrong in here
    you can make more problems  be very sure what you change  and do one thing at a time so you remember and can  dial in again and change it back should you disable something you need. fyi each time you dial in the number it resets to vzw default setting and may look like it did not save setting but it doz. till you dial in again.
    good luck
    ron
    ps im not a vzw rep in any way other then a fellow customer not getting answers.

  • I was making a movie on iMovie, and was trying to use the green screen to make a split screen. I pressed on the green screen button, but the second clip didn't play next to the first, and only the audio played.

    I was making a movie on iMovie, and was trying to use the green screen to make a split screen. I pressed on the green screen button, but the second clip didn't play next to the first, and only the audio played. I tried again with some different clips and some worked and some didn't. This hasn't happened before. What should I do? (I am using iMovie '09)

    No guarantess but try smc and pram resets,

  • JScrollPane shows the first objects

    Hi to all!!
    I am using a panel inside of a JScrollPanel, to every time that I press a certain button in my program a new object is included inside of this panel and consequently when surpassing the size of the panel appears the scroll bar. However, the first objects are always exhibited, because the scroll bar doesn't go down to show the last included object. It would like that was always exhibited the last object. Would anybody know as solving that??? Some exists property for JScrollPane where the scroll bar is always showing the end of the panel and not the beginning.
    At once I thank,
    Santin

    You could try to set focus on the new object once it has been added to the panel. I think the scrollpane will scroll to make sure that the object with focus is always visible.

  • TS1389 I purchased a song on iTunes that is now appearing twice on my library; the first download only plays 37 seconds of the song, the second download will not play & prompts me to authorize the computer to allow it to play.  Suggestions?

    I purchased a song on iTunes that is now appearing twice on my library; the first download only plays 37 seconds of the song, the second download will not play & prompts me to authorize the computer to allow it to play.  Suggestions?

    Im having a similar promblem! Only its doesnt work on my Itunes library and the song ends at 49 seconds. Have you fixed your problem yet?
    p.s. my discussion is on the following page but no one has responded yet as I only just posted it.
    https://discussions.apple.com/thread/4097402

  • How to make a summary column appear only once (in the first page only) in SSRS 2008?

    Hello Everyone,
    How to make a summary column appear only once (in the first page only) in SSRS 2008?
    Regards
    Gautam S
    Regards

    Hi,
    Assuming you have test data like this ;
    select 'abc'as [GROUP],'NN' name , 1 id
    union all
    select 'abc' as [GROUP] ,'PP' name , 1 id
    union all
    select 'abc'as [GROUP],'RR' name , 2 id
    Step1  : take Tablix with row group as your group Name .
    Step2 : right Click on Row Group Details -> Delete-> Delete Group Only
    Step3 : In Count Cell use below expression ;
    =CountDistinct(Fields!id.Value)
    Follow this link;
    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/b6b45917-0a26-4d15-be46-2c6a2697d6e9/distinct-rows-sum?forum=sqlreportingservices#5ffdee06-c2c8-44ea-a3a5-b958488bb6b5
    Thanks
    Please Mark This As Answer or vote for Helpful Post if this helps you to solve your question/problem. http://techequation.com

  • I have problem with my iphone,i activate him with my apple id but i give him a resset and now don't whanna recognize my apple id,this phone wha activated with my apple id,i am the first and only one propert

    i have problem with my iphone,i activate him with my apple id but i give him a resset and now don't whanna recognize my apple id,this phone wha activated with my apple id,i am the first and only one propert

    my imei is 356955067431598 iphone 6 space grey 16gb

  • In iMovie when I move my curser through pictures in the project, I have an empty screen or it shows the first picture only..what might be the problem?

    In iMovie when I move my cursor through pictures in the project, I have an empty screen or it shows the first picture only..what might be the problem?

    Try putting the iPad into recovery mode and see if that fixes it : http://support.apple.com/kb/ht4097

  • Showing data for the first row only

    Oracle Experts ,
    Below is my table in oracle.I wnat show Company ID only for the first row of each company. Table 2 is my output .
    Company Country Company ID
    BARCALAYS UK 1
    BARCALAYS USA 1
    BARCALAYS Australia 1
    Kingfisher UK 2
    Kingfisher INDIA 2
    Kingfisher INDIA 2
    Output Table 2 :
    Company Country Company ID
    BARCALAYS UK 1
    BARCALAYS USA Null
    BARCALAYS Australia Null
    Kingfisher UK 2
    Kingfisher INDIA Null
    Kingfisher INDIA Null
    Please give me a sql query.
    Many thanks in advance .
    Regards,
    Dirasa

    based on if a particular country is appearing twice for the same company and company_id wether to show the company_id for that country or not you may use any of the below queries :)
    /* Will show compan_ID twice if the country is repeated */
      with x as (
          select 'Foo' company_name, 'UK' country, 1 company_id from dual
          union all
          select 'Foo', 'USA', 1 from dual
          union ALL
           select 'Foo', 'USA', 1 from dual
           UNION ALL
          select 'Foo', 'AUS', 1 from dual
          union ALL
        select 'Foo', 'AUS', 1 from dual
          union all     
          select 'Bar', 'UK', 2 from dual
          union all
         select 'Bar', 'USA', 2 from dual
         union all
         select 'Bar', 'India', 2 from dual
    SELECT company_name,country,CASE WHEN rn=1 THEN company_id ELSE NULL END company_id
       FROM (SELECT
       company_name,company_id,country,rank()over(PARTITION BY company_name,company_id ORDER BY country) rn
        FROM x)
    /* Will NOT show compan_ID twice even if the country is repeated */   
      with x as (
          select 'Foo' company_name, 'UK' country, 1 company_id from dual
          union all
          select 'Foo', 'USA', 1 from dual
          union all
          select 'Foo', 'AUS', 1 from dual
          union ALL
        select 'Foo', 'AUS', 1 from dual
          union all     
                 select 'Foo', 'USA', 1 from dual
           UNION ALL
          select 'Bar', 'UK', 2 from dual
          union all
         select 'Bar', 'USA', 2 from dual
         union all
         select 'Bar', 'India', 2 from dual
    SELECT company_name,country,CASE WHEN rn=1 THEN company_id ELSE NULL END company_id
       FROM (SELECT
       company_name,company_id,country,row_number()over(PARTITION BY company_name,company_id ORDER BY country) rn
        FROM x)
    /* Will show compan_ID twice if the country is repeated */
      with x as (
          select 'Foo' company_name, 'UK' country, 1 company_id from dual
          union all
          select 'Foo', 'USA', 1 from dual
          union ALL
           select 'Foo', 'USA', 1 from dual
           UNION ALL     
          select 'Foo', 'AUS', 1 from dual
          union ALL
        select 'Foo', 'AUS', 1 from dual
          union all     
          select 'Bar', 'UK', 2 from dual
          union all
         select 'Bar', 'USA', 2 from dual
         union all
         select 'Bar', 'India', 2 from dual
    SELECT company_name,country,CASE WHEN rn=1 THEN company_id ELSE NULL END company_id
       FROM (SELECT
       company_name,company_id,country,dense_rank()over(PARTITION BY company_name,company_id ORDER BY country) rn
        FROM x)
                    Cheers!!!
    Bhushan

  • Can I have a header on the first page only in pages?

    I only want to have a header on the first page in Pages, not the other pages my work spills over onto. I have tried checking and unchecking the 'node on first page section' which sort of worked when I selected the headers on the pages i did not want but I have now lost the header on the first page.

    I have just solved it!
    When you have entered the header information on the first page you then click on the header on the second page and select 'start new header/footer here' which you can then delete the information and leave blank thus leaving every subsequent page blank.
    Thanks for your help picas and PeterBreis0807

  • How do I put static text in a table on the first page only?

    I need to include a small static table on the first page of a report only. A table expects to be tied to a dataset. 
    Is there a way to include a small static table on the first page without linking it to a dataset? Or a workaround?
    Thanks.
    bill ross

    Hi Billrosspaxedi,
    Thanks for your posting.
    It will be benefit for whom have similar issue to resolve it.
    Regards,
    Heidi Duan
    If you have any feedback on our support, please click
    here.
    Heidi Duan
    TechNet Community Support

  • I only want the header on the first page . How do I remove it from the other pages but leave it on the first page only.

     

    Uncheck the Headers  (and Footers) settings in the Document Inspector.
    Enter the 'header information' directly on the first page, or put it into a text box. There's no need to use Headers if you want the information on only one page.
    Regards,
    Barry

  • Should I call apple for help or

    not even bother with it.
    I went through all this hassle of telling everyone to use my aol email so I could get notifications of mail and adding my aol IM id on their buddy list so that I could video chat with them. However, the video chat has never worked or entirely worked.
    I have the built in isight camera. Linksys router, I have messed with the settings on that to death. Currently the settings are as follows: static ip address, UpnP is enabled, I went though and added all the ports on port range forward.
    I can get video with a friend who has aim on a pc, but I get no sound from her. We have tried yahoo to yahoo, aim to aim, and ichat to aim and still no sound from her. I have a friend who has a mac, and we were unable to connect to each other at all. His said something about being unable to connect.
    I can not get Big Bang board games to access the internet either. Says firewall or NAT is preventing me. I have enabled every port on the router to try and get the games working and still nada.
    My ISP says that they are not blocking any ports, so I don't know what else to do other than call apple.
    I doubt they will even talk to me since the BF purchased the computer. He'd probably have to be here and give them permission to talk to me.
    But there is no reason that I can see for this not to work. I do have a network setup with 2 other computers, but when I was testing it they were not using anything on the internet. MY internet speed test said about 3000 kbps.
    I don't have anyone else to test this out on, my friends won't even try to connect, they are tired of working on this with me.

    Well, we finally got it working. Thanks to defcom!!
    To anyone else having this issue, if you have a linksys or netgear router: you need plugnplay enabled, no special ports open. Which I had, but what I didn't have is the mac firewall ON. That's right, it wasn't on. I didn't have to enable any extra ports in the mac firewall either.
    My ichat would have worked right out of the box with the 10.4.8 update had I not turned off the mac firewall trying to get big bang board games to work.
    If you look up all my post about this issue, you will see all the things I tried. The only thing I did not try was turning the mac firewall back on until today (thanks to whoever suggested it first and thanks to Tony for letting me test connecting to him and telling me to try turning the firewall on).
    So, everything that I tested in the post was undone (set back to original settings...ie ports, the only thing I did not change back was quicktime. It was suggested here that I use below 1.5Mbps . Well it was at 384 kbps. I changed it to 1 and neither worked. Then I ran a speed test and I get well above 1.5, so I went ahead and changed it to 1.5, but this still did not solve the problem. But turning on the firewall did solve it, and I left the QT at 1.5.

Maybe you are looking for

  • What is a text symbol, what does it do (other than mess with my doc)?

    I am working with FM8 in Tech Comm Suite 1 on Windows XP. Some of my docs have text symbols sprinkled liberally throughout the text.  I know you can select the option not to view the text symbols, but they still show up in FM and PDFs and RoboHelp an

  • MX460 Run dll as an App failure

    Help Help!!! Just built Athlon 1800+ ASUS A7S333 MSI Geforce 4 MX 460 XP Pro Unable to access MSI display properties, "run dll as an app encountered a problem". AppName rundll32.exe Appver 5.1.2600.0 ModName mscicpi.dll Am able to access all other di

  • Reg.Debite note alert message during invoice

    Dear Experts We want an alert message during Invoice against Purchase order that "Debite note is raised" if I created debit note advise in F-41. what I should do. Pls advise. Thanks Rajakumar.K

  • Q30: Cannot find sales order for a committed stock item

    I have a few item numbers which show committed stock in item master data/stock but I cannot find an open sales order or even with an open line on a closed sales order. I have tried various query reports without success. Does anyone have a key to unlo

  • "Project is not under source control" Prompt.

    Hello, When I create a simple dictionary type, I get a prompt "Project is not under source control", with following message: Could not check package name. Do you want to continue ? Yes/NO This started happening today as I started working on a new DC.