I have a problem with the solution

import java.util.*;
public class Group extends HashSet<Person>{
    public static void main(String[] args){
    Group g = new Group();
    g.add(new Person("Hans"));
    g.add(new Person("Lotte"));
    g.add(new Person("Jane"));
    g.add(new Person("Hans"));
    g.add(new Person("Jane"));
    System.out.println("Total:" + g.size())
    public boolean add(Object o){
    System.out.println("Adding: " + o);
    return super.add(o);
    class Person{
       private final String name;
       public Person(String name){this.name = name;}
       public String toString(){return name;}
    }Which of the following occur atleast once when the code is compiled and run
Ans: The code does not compile, the problem here is in groups add method. It should have been add(Person) since the class extends HastSet<Person>. So this doesnt comple.
What would happen if you fixed this code changing add(Object) to add(Person).
My problem is if we changed add(Object) to add(Person) we will have to change the implementation in the Group class also for the following code
g.add(new Person("Hans"));
    g.add(new Person("Lotte"));
    g.add(new Person("Jane"));
    g.add(new Person("Hans"));
    g.add(new Person("Jane"));to something like
g.add("Lotte");am i correct in my inference?

I don't see the use of your Group class in any case. It is just a wrapper around HashSet.
Anyway, the HashSet uses generics to fix the exact dilemma that you have (being able to safely store different types of objects in it without having to subclass it for every object type), so if you want to be able to use your Group class to behave in the same way you'll have to make it using a generic type as well. Something like:
public class Group<T> extends HashSet<T>{
public boolean add(T o){
    return super.add(o);
public static void main(String[] args){
    Group<Person> g = new Group<Person>();
}(Typed from memory, could have a typo)

Similar Messages

  • TA38607 I have a problem with the "beep".

    I have a problem with the "beep". I have an iPhone 4S and I did the upgrade to the iOS 6 and now every time I get and incoming call while on the phone I always miss it because it never let me knows. How do I fix this? ...please

    Go into the Device Manager. Expand the battery device, select the ACPI-Compliant Battery Control Method device, right-click it and select uninstall. After you have done that, right-click any device in the Device Manager and select scan for hardware changes. Your operating system will reinstall the  ACPI-Compliant Battery Control Method device. 
    Post your results whether they are negative or positive to keep us posted.
    ****Please click on Accept As Solution if a suggestion solves your problem. It helps others facing the same problem to find a solution easily****
    2015 Microsoft MVP - Windows Experience Consumer

  • I have a problem with the indicator for power on the side of my HP DV6-1341el.

    I have a problem with the indicator for power on the side of my HP DV6-1341el. Insert the adapter's power jack on the notebook in front of the LED battery charging works, windows detects that the battery is charged, but if I use the diagnostic programs, they tell me they found that the computer is running on battery power and not AC mode.
    Where is the problem?
    I have also made the maneuver for the recognition by the operating system of the battery and does not seem to be there the problem.
    If I use the laptop without battery in AC mode happens that led to the side of the notebook blinks twice, three times and then goes off when I put the power jack.

    Go into the Device Manager. Expand the battery device, select the ACPI-Compliant Battery Control Method device, right-click it and select uninstall. After you have done that, right-click any device in the Device Manager and select scan for hardware changes. Your operating system will reinstall the  ACPI-Compliant Battery Control Method device. 
    Post your results whether they are negative or positive to keep us posted.
    ****Please click on Accept As Solution if a suggestion solves your problem. It helps others facing the same problem to find a solution easily****
    2015 Microsoft MVP - Windows Experience Consumer

  • Hello, i have a problem with the download of the testversion of photoshop CC.

    Hello, i have a problem with the download of the testversion of photoshop CC. After 3 minutes after beginning with the download always appears "failure A12E5" and the download is stopping. Who has a good idea for the solution of my problem?

    Hello, here are some troubleshooting steps that relate to download problems: http://helpx.adobe.com/creative-cloud/kb/troubleshoot-cc-installation-download.html

  • I have a problem with the keyboar.when i push the key enter it doens't work

    i have a problem with the keyboar.when i push the key enter it doens't work

    Final Cut Express was discontinued about 18 months ago, before the release of Lion (10.7).  It is no longer a supported product and was never supported on Lion, nor on Mountain Lion.
    While some FCE users have had success running FCE on Lion, many have reported problems including problems with chroma keying.   I do not recall any solution to the chroma keying problem, but you might try searching this Forum to see what others have discovered or tried.
    Final Cut Pro X is the app supported on Lion & Mountain Lion, and the future direction Apple has taken.  Since your computer lab has already moved to Lion (10.7.5) and presumably will move to Mountain Lion in the future, you should begin the process of moving to Final Cut Pro X.  I appreciate there are implications for cost, training, inconvenience and re-doing lesson plans.  But technology moves on and at some point we need to move with it too.

  • I have a problem with the touchsmart 420pc, after a running time (2 hour approx) is turned off,

    good afternoon, I have a problem with the touchsmart 420pc, after a running time (2 hour approx) is turned off, probably warming, but this rare, is suddenly going slow parapadear and image.
    also sounds like when damaged ballasts for lamps,
    ANYONE know what could be the cuasa and / or what is causing this.
    greetings and thanks in advance

    Hi,
    Please write your TouchSmart model number, which system are you using and country of purchase.
    Resource:
    How Do I Find My Model Number?
    ** Say thanks by clicking the "Thumb up" icon which is on the left. **
    ** Make it easier for other people to find solutions, by marking my answer with "Accept as Solution" if it solves your issue. **

  • I have a problem with the sync between iTunes and ipad2. I can not see the files in iPad. Help me please.

    I have a problem with the sync between iTunes and ipad2. I can not see the files in iPad. Help me please.

    Cannot see what files ? Music (synced music should appear in the iPod app), films/TV shows (Videos app), documents ... ?

  • Since updating to Firefox 4.0.1 I have a problem with the website shortcuts I have on on desktop.

    <blockquote>Locking duplicate thread.<br>
    Please continue here: [/questions/821825]</blockquote><br>
    Since updating to Firefox 4.0.1 I have a problem with the website shortcuts I have on on desktop. I have a few of these shortcut to website I use a lot. When I click on the short I get the message "windows cannot find [then the web address] make sure you typed the name correctly, then try again. To search for a file, click the Start button, and then click Search." I tried deleting the shortcut and setting it up again but still get the message.

    Try to redo the default browser and make another browser like IE the default browser and then let Firefox do it again.
    See:
    * http://kb.mozillazine.org/Default_browser
    * [[Setting Firefox as the default browser does not work]]

  • Hello, I have a problem with the iPod, is that the iPod does not sync all the songs that are on my Itunes. I have 373 songs on the iPod and iTunes 512 in ... What do I do?

    Hello,i have a problem with the Ipod,is that the Ipod doesn't sync all the songs in my Itunes. I have 373 songs in my Ipod and 512 sons in my Itunes. What do i do?

    Hello,
    I take it you haven't unticked any of the songs listed on your iTunes Library? Also have you tried selecting all your songs which you wish to add to your iPod, and dragging them over your Devices "iPod Nano"; and seeing if that copies all songs on to your iPod?
    Another idea is just check that your iPod has enough space for the rest of your songs to be added to your device.
    Hope this helps.

  • I  have a problem with the synchronisation of my iPhone and iPad with Outlook 2007 on my 64-bit Windows 7  PC. For several years, I have had no problems with the synchronisation by cord connection and iTunes between these programmes. However, a few months

    I  have a problem with the synchronisation of my iPhone and iPad with Outlook 2007 on my 64-bit Windows 7  PC. For several years,
    I have had no problems with the synchronisation by cord connection and iTunes between these programmes. However, a few months ago I decided to use Mobile Me. However, there were problems with duplication of calendars and then “rogue events” – which could not be deleted – even if deleted on Outlook and on the iPhone (or both at the same time) – they would just reappear after the next synchronisation.  All other synchronisation areas (eg Contacts, Notes etc) work fine.
    I have looked for help through the Apple Support Community and tried many things.  I have repaired my Outlook. I have repaired my .pst file in Windows. I have re-installed the latest version of iTunes on my PC. I have re-installed the firmware on my iPhone. I have tried many permutations on my iPhone. I have closed down all Mobile Me functions on the iPhone. I have spent upwards of 24 hours trying to solve this problem.
    What am I left with? Outlook works seamlessly on my PC. My iPhone calendar now has no events from  my calendar, but does not synchronise through iTunes. Nor does it send events initiated on the iPhone to the Outlook. I am at the point of abandoning iPhones and iPads altogether.  I need to have a properly synchronising calendar on my phone.  Do you have any suggestions?

    In the control panel goto the "Lenovo - Power Manager" and click the battery tab, there is a maintenance button in there that will let you change the charging profile for your battery.   (from memory, so exact wording may be off)
     The lower the numbers you use there, the longer the battery *should* last.    These batteries degrade faster at higher charge levels, however storing them at too low of levels is also not good for them... I've read that 40% is optimal, but just not realistic if you use your computer.
    --- ThinkPad T61 / Win 7 / Core 2 / 4gb RAM / Nvidia / Still used daily --- ThinkPad Edge 15/ i5 / Win 7 / TrueCrypt / 8gb RAM / Hated it, died at 1 yr 1 mo old --- ThinkPad T510 / Win 7 / TrueCrypt / i5 / 8gb RAM / Nvidia / Current primary machine --- ThinkPad X220 / i7 / IPS / 4gb / TrueCrypt / My Road Machine

  • HT3310 i have a problem with the headset of my ipod nano 4th gen. the right side don't have a sound. It comes in and out.  what do I need to do?.. I am using the original headset eversince. I took it to an Apple Mac Center I was told they can't do anythin

      I have a problem with the headset of my ipod nano 4th gen. the right side don't have a sound. It comes in and out.  what do I need to do.. I am using the original headset eversince. I tool it to a Apple Mac Cennter and Taked with a Service Center Rep. And he told me that they can't do anything because they don't repair the ipod they didn;t even look at it. I was told instead to buy a new one. I was very disappointed.. This is already my 5th ipod though i am planning to buy a new one.. I still want it fixed so I can give it to my little sister

    From the OP: "My old computer got a virus and when that happened all my music was lost. "
    They don't have the music on their computer so they cannot transfer the iTunes folder, from the computer to their iPod and then to the new computer. And if they try to enable disk use on the iPod it will erase all the music that is on it. The method you cited is moving the files in a data format using the iPod as a flash drive. It doesn't work if they are in music format. That is why I suggested Yamipod.

  • I have a problem with the iTunes Store, I have an ipod and an iphone 2. I have a PC with Windows Vista Home Premium 2007, entering into iTunes Store on the main screen I get only AppStore, Podcast and iTunesI have a problem with the iTunes Store, I have a

    I have a problem with the iTunes Store, I have an ipod and an iphone 2. I have a PC with Windows Vista Home Premium 2007, entering into iTunes Store on the main screen I get only AppStore, Podcast and iTunes U. In my screen I get only ipad2 Podcast, iTunes U Downloads. My problem is I can not access any application to download music, videos, books, etc..
    ITunes will be installed wrong or what should I do to activate these options?

    Go to the front page of the Store, and click Change Country.  Make sure it is set to the country where you actually are. 
    Then you will be able to see everything that is for sale in your country, which, depending where you live, might or might not include music.

  • I have a problem with the icon in the menu bar MacBooster Beta 3 I can not delete

    I have a problem with the icon in the menu bar MacBooster Beta 3 I can not delete
    www.advancedmaccare.com
    and installed and uninstalled the program and past cleanApp or ccleaner programs and nothing works
    <Link Edited By Host>

    Beta = buggy software.  You need to contact the vendor. 

  • How do I save a PDF ready for print. I have a problem with the fonts. The fonts are blurry after pri

    How do I save a PDF ready for print. I have a problem with the fonts. The fonts are blurry after printing. There is a trick in saving PDF.

    Hi el_giclee,
    Important to note from the beginning is that when you create your Photoshop document make sure you chose 300 Pixels/inch as your resolution.
    I'm interested in seeing your Save Adobe PDF dialog box after you choose to save the PDF.
    Could you post a screenshot of this dialog box with the Compression menu selected on the left side?
    It's a good idea to select High Quality Print or Press Quality in the Adobe PDF Preset menu at the top of this box. It will automatically select the best default settings for a printed piece.
    Michael

  • TS3938 I have a problem with the CD player plays some species, others give me this letter no longer supported PowerPC

    I have a problem with the CD player plays some species, others give me this letter no longer supported PowerPC

    Educational software suffers from having been written many years ago, but the financial market is not such to give the publisher much incentive to update the software.
    The problem for you is that Top Notch 2 with ActiveBook was written and released by Pearson back when Macs utilized the PowerPC CPU platform.  In 2006, Apple migrated the Macs to Intel CPUs, but released their Operating Systems with an invisible translation program, Rosetta, so that the user could continue to use their existing library of PowerPC applications and take time to update them as needed.
    The problem arises in that Apple no longer continues to update Rosetta for inclusion in Lion and now Mountain Lion, so that your CD-ROM cannot be executed on your Lion Mac.
    Since Pearson looks unlikely to rewrite and release an Intel version of Top Notch 2, you must find a workaround that will play your CD-ROM and allow you to continue utilizing your ActiveBook.
    You do not indicate which model of Mac you are using.  If you upgraded it to Lion from Snow Leopard, you have these workarounds:
    1.  Revert to Snow Leopard
    2.  Partition your hard drive or add an external hard drive and install Snow Leopard into it.  This will allow you to "dual-boot" into Snow Leopard when you need access to run Top Notch 2.  You would then have to "dual-boot" back into Lion when you needed access to those features required by Lion.
    If you purchased a new Mac that came with Lion, you only have one workaround available to run Top Notch 2: 
    3.  Install Snow Leopard (with Rosetta) into Parallels
                                  [click on image to enlarge]
    There is an easier way to run your Top Notch 2 in Parallels if cost is not a significant factor for you.  You must purchase Snow Leopard Server from a third party souce, such as eBay, which when sold by Apple was $499 or more.  I now see that it can be purchased on eBay for as little as $51.  Parallels allows for easy installation of Snow Leopard Server into Parallels.
    If cost is a factor, then use the link above the photo to follow my instructions on how to install Snow Leopard client ($19.99 from Apple) into Parallels and achieve the same result.
    Lastly, you could purchase a used Mac that will allow Snow Leopard to be the boot OS X installed (wth the optional Rosetta installed).  But this seems like an expensive alternative just to run one piece of software; and subject to hardware failure without notice or recourse.

Maybe you are looking for

  • Upgrading from Acrobat 5 to newer acrobat

    I am a graphic designer and use acrobat all the time. I have just purchased a new computer with Windows 7 and have installed Acrobat 5 from the disc I had, it seems to be working but I'm sure a later version would be an improvement. Could you tell me

  • SunONE 6.1 admin console problem

    Hi, I've got 6.1 installed on a machine running a fully patched Solaris 8.5/03 install (including patches recommended by SunONE webserver 6.1) on an E250. When we start the admin console we get the following error message in the errors file. CORE3274

  • Tree does not show node correctly but node are inserted well ?

    hi, i am haveing tree with 1. Root node (grand parent (only one)) 2.Parent nodes(many nodes) 3.child nodes(many nodes) i add child node in a particular parent node . this is done dynamically when socket thread found any any user .when socket listener

  • Vnc without dtlogin, I.e. using gnome display login?

    Greetings all, Anyone out there use the xvnc server that comes bundled with u5 or u6 successfully? I've been able to get it to run with the default 'cde-login', but due to a number of security issues, we are strongly recommended to not use it (Federa

  • HT201359 I cnot buy clash of clans

    Canot buy in clach of clans