Polymorphism example

There are 3 examples of polymorphism.
abstract class,interface and method overloading
methodoverloading(in the class having a method in same return type but different signature)
here i am little bit confused about different signature.
if i m not wrong its mean different access modifier(public,private,protected)

Think about the ways you can declare methods without conflicts with the compiler saying that "you cannot have more of the same method declared".
What makes a method unique from others with the same name is its signature.
Go try it out for yourself.

Similar Messages

  • Downstream polymorphism example for Idea Exchange comment

    Because I cannot put attachments on comments in the Idea Exchange, I am posting the VIs here and linking to this post from there.
    This is for this idea.
    Solved!
    Go to Solution.
    Attachments:
    PolyVIClassSelector.zip ‏39 KB

    I'm trying to actually implement this idea in LV 2012 SP1 and I'm getting an error which seems to specifically prevent me doing what I want to do.
    "The property definition folder named "Events" overrides a property in a parent class, but the overriding property accessor VI in the child class has a different filename than the accessor VI in the parent class."
    Well, yeah, that's what I want to do.  The code provided by AQ works without error, but trying to reproduce a similar behaviour in my own code produces this error.  I have also created static VIs which reside within the property folder, each with a different datatype and different name but with the same name property folder.
    What am I doing wrong?
    The property of interest in "Parent" and "Child" is "Events".  Both of these VIs return different datatypes for each class.  Both are static VIs (non-DD).
    Oh, I think I see the big problem here.... The classes in AQs code are not inherited from each other (They are not parent and child).  This ability only seems to work between "unrelated" classes.  This is a major problem for me.  I don't want an "Override" functionality, I just want it to behave as it does in AQs example.
    Looks like I have to go back to maintaining polymorphic VIs....... Bah humbug.
    Shane.
    Say hello to my little friend.
    RFC 2323 FHE-Compliant

  • Difrence bitween overloading and overriding

    Plese give the definition & example for polymorphism

    Polymorphism is of two types
    1) static or design time polymorphism
    2) dynamic or run time polymorphism
    example for design time polymorphism is overloading (i.e) a method with same name shares diff signatures
    For eg: arithmetic(int,int)
    arithmetic(int,int,int)
    example for run time polymorphism is overriding (i.e) a method with same name exists in both parent class and child class.
    At run time it will be decided which method to call based on the object which calls it
    Hope this clarifies yr query
    Regards
    Jansi

  • Perparing for Practical SKills test in Java

    Hello
    i have a question that has been bothering me, currently studying ICA 40505
    programming at swinburne uni in melbourne, okay my new instructor told me to write down
    super class
    test class
    simple GUI
    but i am a bit fustrated because its not specifc enough, so i am after a good source of practice test sheets to help prepare for my practical skills test...
    plus any tips on how you prepare for tests and assessments..
    cheers Lee

    If you are frustrated about these exam hints, I strongly recommend that you do this before trying practice exams:
    * Study and understand the course material that was supplied by Swinburne
    * Use a search engine to find additional info on course material you don't understand (e.g. Google "java Super class" or "java polymorphism example")
    * Complete all lab tasks and course examples again.
    For practice exams, try:
    * [Free Proficiency Assessments|http://www.sun.com/training/certification/assessment/index.jsp]
    * [Free Sun training|https://learning.sun.com/sites/stimulus/]
    * [Practice exam|http://au.sun.com/training/catalog/courses/WGS-PREX-J019C.xml]

  • Could anyone please explain Polymorphism to me with Example?

    I am trying to learn the concept of Polymorphism in Java and I am having a tough time understanding what it is. I keep confusing it with inheritance which I am now comfortable with but I don't get what the book says about polymorphism and a lot of tutorials I have seen do not seem to explain it as to a layman. Please Help a newbie to programming understand POLYMORPHISM
    Java NewBie

    Here's a real-world example: I had a large data structure (a tree, basically) whose contents aren't relevant to this discussion. I also had a variety of functionality required, a bunch of which required visiting every node of the data structure.
    Now, I could write the same tree-spanning code over and over again for each separate bit of functionality that required it. Or try to create a library function that spanned the tree (although in reality, it's hard to write library functions like that without a degree of polymorphism). But these were either redundant or clumsy or both.
    So the approach I took was to add a "visitAll" method to the data structure. (This is actually an example of encapsulation -- the data and the operations on the data are stuck together.) The visitAll method took an object, and for each node in the tree, it invoked a method (let's call it "absorb") on the given object.
    continued...

  • How to create ADF UI based on polymorphic view objects

    Hi,
    I'm using JDeveloper build JDEVADF_11.1.1.3.PS2_GENERIC_100408.2356.5660. I created a simple application based on Steve's example #10 [url http://blogs.oracle.com/smuenchadf/examples/]ViewRow and EntityObject Polymorphism.
    I added a men-only attribute "Age" to the "Men" VO and filled it with an arbitrary value in MenRowImpl.java:
    public String getAge() {
         return (String) "45";//getAttributeInternal(AGE);
    }Running the TestModule works perfectly - a row of type "Men" displays the "Age" attribute whereas a row of type "Women" doesn't.
    Afterwards, I setup an ADF ViewController Project and created a JSPX with a read-only form based on the "People" datacontrol with navigation buttons. Running that page always shows the same set of attributes independent of the row type. That's expected behaviour because the binding is defined at design time.
    So my question is: can I somehow achieve the same behaviour for polymorphic VOs as the business component tester shows?
    Kind regards,
    Markus

    Andrejus' example shows how to calculate different values for the same attribute based on overridden view objects. That's not exactly what I'm looking for. I need to display a (at least partly) different set of attributes that changes while the user scrolls through the records of the result set.

  • Concept of Abstraction and Polymorphism

    Hi friends,
    I'm just new to Java.I studied a little bit of C, I'm currently studing VB and Java.
    There are one or two concepts in Java that are very hard to grasp for me.
    The first is abstraction and the second is polymorphism.
    Can anybody outline to me in simple words(use simple example if needed)what those 2 concepts are all about?
    Thanks a lot
    Marco

    In your example, you could make Vehicle an abstract
    class. You can't simply have a vehicle, but you can
    have a car which IS a vehicle. In your abstract class
    Vehicle, you might define an abstract method public
    int getSeats() (you want it to be abstract because it
    changes from one type of vehicle to the next). So the
    class Car extends Vehicle, overrides the method
    getSeats() and returns 5. The class Ute extends
    Vehicle, overrides the method getSeats() and returns 2
    (you might make a SuperCabUte that extends Ute and
    returns 5, or whatever).Radish is right,
    Think of it as modelling of real life. You would generalise the description of your car as a Vehicle (abstraction, which can be implemented as an interface in Java) where in fact you own a car
    Similarly you can have an inteface called RealEstate where in fact you own a TwoStoreyHouse ( a class that implements the RealEstate interface)
    the interface can describe the general 'characterstics' of real estate properties ie land size, council rates etc.
    HTH...hey....

  • RE: Polymorphism - retrieving type information from thedatabase or how

    Don,
    Ok but if I was to model a real restaurant, I would then have a head chef
    that can then delegate to other chefs. This head chef would have the
    additional task of coordinating the completion of subservient chefs. This
    does not and would not mean that the head chef is stuck (or partitioned) in
    one part of the kitchen. Further a head chef would most likely also be a
    chef so that he would be running around the kitchen using and interacting
    with different objects to get his part of the recipe completed. Then once
    all chefs have completed their part of the recipe the head chef could return
    the meal.
    I would also point out that it does not make sense to me to be talking about
    the chef and its ability to scale. I would look that the resource limited
    devices that must be used to prepare meals to see scalability. In this case
    the grill, the stove and the microwave. Scalability of the restaurant is a
    function of the amount of resource limited devices versus the number of
    process (i.e. chefs) that need to use those devices concurrently and the
    amount of time they require access to those devices. By talking about chefs
    as if they are the scalability limiting factor seems to bring us back to the
    notion that the chef is a manager object that is shared. And again I come
    back to the question, why?
    You may now think that in a real restaurant, there are only so many chefs so
    why not make it a shared service? Well in a real restaurant there are only
    so many of any object, but this is not a consideration in our restaurant
    model. In our "virtual" restaurant hiring a chef is as easy as:
    Chef = new;
    And of course chefs are of zero mass so there can be a whole lot in the
    kitchen. Now assuming the Grill, Stove and Microwave map to physical
    objects in our computing environment, then that is the limiting factor and
    are therefore partitioned. Whenever communication has to go through a
    single source, then scalability breaks down. I fear that too many people
    make shared objects and create communication bottlenecks where they simply
    don't exist. The only place your scalability bottlenecks should exist is in
    the actual resource limited objects of your computing environment. Simply
    said, if something isn't a resource limited object, then why is it shared?
    If anyone is not clear how to architect an application independently of the
    business model, then I would suggest looking at various framework products
    and reading some technical architecture white papers to get a different, and
    possibly enlightening, point of view.
    Mark Perreira
    Sage IT Partners.
    -----Original Message-----
    From: Don Nelson [mailto:[email protected]]
    Sent: Wednesday, June 17, 1998 9:04 AM
    To: Mark Perreira
    Cc: [email protected]
    Subject: RE: Polymorphism - retrieving type information from the
    database
    Mark,
    First, I completely agree about the naming. I purposely used rather
    euphamistic names for these "managers", since I see many convoluted names
    for common things in various applications. But that is a topic for another
    thread...
    Simply because there is a "manager" of some type, does not imply that it is
    chained to a particular duty. However, let's look at a real life case. In
    a large restaurant, you would rarely see a chef chopping carrots or serving
    dishes to customers. Those are the responsibilities of the sous-chef and
    the waiter. So, we see that the chef does not really follow the food
    around. Why not? Because it simply doesn't scale. When scalability isn't
    a problem, (the restaurant isn't that popular, for example) the chef has
    some lattitude to accept more responsibility, and might even get involved
    with purchasing, etc.
    In the real world, the more scalable something has to be, the narrower the
    responsibilities are for each of the participating members.
    Don
    At 12:59 AM 6/17/98 -0700, Mark Perreira wrote:
    Don,
    One thing that always baffles me is when should an Object get the moniker
    "Manager." This practice seems to tell me a couple of things about these
    objects. In general when someone makes reference to a "Manager" objectthat
    it is probably a service object and probably contains no or very little
    attribution. The question is why? If I am developing an object model why
    am I thinking about such implementation issues.
    Surely if you are trying to model cooking an egg I would not see
    "SustenancePreparationManager" in your model. Using a more common term I
    would still be alarmed to see "CookManager" in your model. What does the
    CookManager manage? Does it manage other cooks or eggs. Maybe it shouldbe
    called an EggManager, but that doesn't make sense. How about just Cook.
    There that seems like the real world. And this brings me to a problem in
    the analogy. Conjuring up managers in a model can sometimes make you missa
    container. For example, I would say that if we wanted to model the real
    world, then eggs is a specialization of ingredient that is contained by
    recipe that can be given to a cook to be prepared.
    I may have many cooks (objects) that can prepare recipes and my application
    architecture not the object model needs to deal with how to best let those
    cooks utilize the grill, stove and microwave that sits on different
    partitions on my server. My cooks can move around and when they do they
    take their ability to know how to cook with them. In the real world Iwould
    expect a cook to use the right appliance to prepare the recipe based on its
    contents. I would not chain every cook to its appliance and them make me
    responsible for giving the right cook the right recipe. This is what
    managers can cause. They cause the consumer of cooks to know which cookcan
    prepare what recipes based on where they are chained. This then makes me
    know something about cooking. And if I don't know anything about cooking I
    can only image what my egg would look like if I accidentally gave therecipe
    to the cook stationed at the microwave.
    Ok Ok, I have seen many architectures use facades to hide the fact that I
    like to chain my cooks to their appliance. But what is that. I have gone
    to restaurants and I don't know what a cook facade is. If I ask themanager
    to present the cook facade manager employee I would probably be met by the
    bouncer employee.
    So what is the answer? Well for a start keep the application architecture
    out of the model. The model should stand alone in describing the
    interactions required to satisfy use cases. Second find an architecture
    that describes a more responsibility driven design and how that design and
    can map your business object behavior to a physical implementation with
    appliances and cooking rules. And lastly, don't be so quick to chain your
    cooks to their appliances. Give them some control over where they cook
    their recipes, after all that is what they do.
    Mark Perreira
    Sage IT Partners.
    -----Original Message-----
    From: [email protected]
    [<a href="mailto:[email protected]">mailto:[email protected]]On</a> Behalf Of Don Nelson
    Sent: Tuesday, June 16, 1998 2:07 PM
    To: Nick Willson
    Cc: [email protected]
    Subject: Re: Polymorphism - retrieving type information from the
    database
    This thread is switching context a bit, but I would add one thought tothe
    idea of encapsulating behavior. One of the advantages to OO is that it
    helps us model real world behavior. In the real world, I would not askan
    invoice to stuff itself into an envelope and mail itself to its
    customer; I
    would not ask my vehicle to fuel itself or change its own oil; I wouldnot
    tell an egg carton to ask one of its eggs to fry itself. Even if these
    things were physically feasible, I could list a number of reasons why I
    still wouldn't want to do them. That is why we haveVehicleRepairManagers
    and SustenancePreparationManagers (aka, "Mechanics" and "Cooks").
    Don
    At 11:28 PM 6/15/98 -0700, Nick Willson wrote:
    Tim,
    You've had lots of good suggestions so I hope you won't mind an attempt
    at another one. The consensus seems to be for your option (1) for the
    Vehicle table, and Steve's example of a GenericConstraint (taking the
    place of your Vehicle) is probably how most people would go about
    answering your question. I don't have much to add to that, just wanted
    to offer something about where the persistence mechanism lives and how
    things look to clients that depend on it.
    Suppose for a moment you think about the Vehicle classes' persistence as
    being just one aspect of their behavior. In addition to persistence,
    you might have to implement security, or locking for concurrent access,
    or caching of vehicle objects to improve performance, and of course you
    want to calculate the vehicle tax and probably do other things with
    Vehicles too.
    You can put the persistence aspect of Vehicles into a
    PersistenceObjectManager, but then the others need somewhere too. If
    you use a bunch of Managers (one for security, one for locking...) then
    each class's behavior is scattered across these various Manager classes,
    each of which has to know about many classes. Or if you use one Manager
    class, it's going to know still more, plus you are forced to implement
    all the behavior in (or at least via) that manager's partition.
    An alternative would be to keep all the Vehicle classes' behavior
    encapsulated together, so a client always makes requests to a Vehicle,
    and the Vehicle delegates the implementation of requests to a chain of
    handler objects that hang off the vehicle object (a handler for
    security, another for persistence, and so on).
    One of the nice things about this is, the handlers can be responsible
    for going to another partition (if necessary), e.g. to perform
    persistence operations, or for more business-specific operations like
    tax calculations. And because the handlers are smart, you don't have to
    put a lot of code into service objects, the SOs can stay pretty simple.
    This isn't an approach you'll see in Express, so I hope of it's of some
    interest.
    General wrote:
    Part 1.1 Type: Plain Text (text/plain)
    Encoding: quoted-printable--
    Nick Willson
    SCAFFOLDS Consultant,
    Sage IT Partners, Inc.
    (415) 392 7243 x 373
    [email protected]
    The Leaders in Internet Enabled Enterprise Computing
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:<a href=
    "http://pinehurst.sageit.com/listarchive/">http://pinehurst.sageit.com/listarchive/</a>>
    >>>
    >>>
    >>
    >>
    ============================================
    Don Nelson
    Regional Consulting Manager - Rocky Mountain Region
    Forte Software, Inc.
    Denver, CO
    Phone: 303-265-7709
    Corporate voice mail: 510-986-3810
    aka: [email protected]
    ============================================
    "When you deal with higher numbers, you need higher math." - Hobbes
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:<a href=
    "http://pinehurst.sageit.com/listarchive/">http://pinehurst.sageit.com/listarchive/</a>>
    >>
    >
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:<a href=
    "http://pinehurst.sageit.com/listarchive/">http://pinehurst.sageit.com/listarchive/</a>>
    >
    >
    ============================================
    Don Nelson
    Regional Consulting Manager - Rocky Mountain Region
    Forte Software, Inc.
    Denver, CO
    Phone: 303-265-7709
    Corporate voice mail: 510-986-3810
    aka: [email protected]
    ============================================
    "When you deal with higher numbers, you need higher math." - Hobbes
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:<a href=
    "http://pinehurst.sageit.com/listarchive/">http://pinehurst.sageit.com/listarchive/</a>>

    Don,
    You are absolutely correct. But this is where I honestly think you are
    missing the point. While the mail program sends the mail, my mail message
    has an interface (i.e. send button) which can delegate that to the mail
    program. This makes it nice and simple for me the consumer of the mail
    program. It also means I can think of mailing by focusing on the interface
    (i.e. the button). It would suck if every time I wanted to mail something I
    had to identify the correct pop server to send it to (i.e the MailManager).
    Mailing something is the collaboration of the setup information of the mail
    program and my mail message. If I were to model this my mail object would
    indeed have a send method that could delegate to the correct mail servers.
    This is just simplicity of interface and it is a good practice in UI
    development just as it is in business model development. A simpler
    interface, I think we can all agree, provides for a better and quicker
    understanding.
    Mark Perreira
    Sage IT Partners.
    -----Original Message-----
    From: [email protected]
    [<a href="mailto:[email protected]">mailto:[email protected]]On</a> Behalf Of Don Nelson
    Sent: Thursday, June 18, 1998 9:22 AM
    To: Nick Willson
    Cc: [email protected]
    Subject: Re: Polymorphism - retrieving type information from the
    database
    Nick,
    It turns out that your message does not, indeed send itself. Your mailing
    program does that.
    Don
    At 11:54 PM 6/17/98 -0700, Nick Willson wrote:
    Hey Don,
    In the real world, no, you can't tell an invoice to put itself into anenvelope
    and mail itself. You have to know about stamps and post boxes and wherethey
    are located. But isn't it nice that in software you don't have to followthe
    real world very closely if you don't want to?
    Above the top left hand corner of this message I'm typing right now, thereis a
    send button which lets me tell the message to 'stuff itself into anenvelope
    and mail itself'. Why wouldn't you want to do that?
    Don Nelson wrote:
    This thread is switching context a bit, but I would add one thought to
    the
    idea of encapsulating behavior. One of the advantages to OO is that it
    helps us model real world behavior. In the real world, I would not askan
    invoice to stuff itself into an envelope and mail itself to its customer;I
    would not ask my vehicle to fuel itself or change its own oil; I wouldnot
    tell an egg carton to ask one of its eggs to fry itself. Even if these
    things were physically feasible, I could list a number of reasons why I
    still wouldn't want to do them. That is why we haveVehicleRepairManagers
    and SustenancePreparationManagers (aka, "Mechanics" and "Cooks").
    Don
    At 11:28 PM 6/15/98 -0700, Nick Willson wrote:
    Tim,
    You've had lots of good suggestions so I hope you won't mind an attempt
    at another one. The consensus seems to be for your option (1) for the
    Vehicle table, and Steve's example of a GenericConstraint (taking the
    place of your Vehicle) is probably how most people would go about
    answering your question. I don't have much to add to that, just wanted
    to offer something about where the persistence mechanism lives and how
    things look to clients that depend on it.
    Suppose for a moment you think about the Vehicle classes' persistence as
    being just one aspect of their behavior. In addition to persistence,
    you might have to implement security, or locking for concurrent access,
    or caching of vehicle objects to improve performance, and of course you
    want to calculate the vehicle tax and probably do other things with
    Vehicles too.
    You can put the persistence aspect of Vehicles into a
    PersistenceObjectManager, but then the others need somewhere too. If
    you use a bunch of Managers (one for security, one for locking...) then
    each class's behavior is scattered across these various Manager classes,
    each of which has to know about many classes. Or if you use one Manager
    class, it's going to know still more, plus you are forced to implement
    all the behavior in (or at least via) that manager's partition.
    An alternative would be to keep all the Vehicle classes' behavior
    encapsulated together, so a client always makes requests to a Vehicle,
    and the Vehicle delegates the implementation of requests to a chain of
    handler objects that hang off the vehicle object (a handler for
    security, another for persistence, and so on).
    One of the nice things about this is, the handlers can be responsible
    for going to another partition (if necessary), e.g. to perform
    persistence operations, or for more business-specific operations like
    tax calculations. And because the handlers are smart, you don't have to
    put a lot of code into service objects, the SOs can stay pretty simple.
    This isn't an approach you'll see in Express, so I hope of it's of some
    interest.
    General wrote:
    Part 1.1 Type: Plain Text (text/plain)
    Encoding: quoted-printable--
    Nick Willson
    SCAFFOLDS Consultant,
    Sage IT Partners, Inc.
    (415) 392 7243 x 373
    [email protected]
    The Leaders in Internet Enabled Enterprise Computing
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:<a href=
    "http://pinehurst.sageit.com/listarchive/">http://pinehurst.sageit.com/listarchive/</a>>
    >>>
    >>>
    >>
    ============================================
    Don Nelson
    Regional Consulting Manager - Rocky Mountain Region
    Forte Software, Inc.
    Denver, CO
    Phone: 303-265-7709
    Corporate voice mail: 510-986-3810
    aka: [email protected]
    ============================================
    "When you deal with higher numbers, you need higher math." - Hobbes--
    Nick
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:<a href="http://pinehurst.sageit.com/listarchive/">http://pinehurst.sageit.com/listarchive/</a>>
    >
    >
    ============================================
    Don Nelson
    Regional Consulting Manager - Rocky Mountain Region
    Forte Software, Inc.
    Denver, CO
    Phone: 303-265-7709
    Corporate voice mail: 510-986-3810
    aka: [email protected]
    ============================================
    "When you deal with higher numbers, you need higher math." - Hobbes
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:<a href=
    "http://pinehurst.sageit.com/listarchive/">http://pinehurst.sageit.com/listarchive/</a>>
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:<a href=
    "http://pinehurst.sageit.com/listarchive/">http://pinehurst.sageit.com/listarchive/</a>>

  • JAXB Polymorphism of little use

    HI all.
    I am finding little use in JAXB's polymorphism. As such, I think I'm going to need to switch to another framework that has a more useful polymorphism feature (or else none at all).
    As indicated below, I have a schema that includes a "Person" complex type, and an "Employee" complex type that extends it. There is also an element "people" that is a sequence of "Person" elements. I have used JAXB-generated classes to add instances of Person and Employee (generated classes) to an instance of the People class. The marshaller then erroneously outputs the extensions to Person found in Employee (see below).
    Having seen this, I wonder what use polymorphism (in the classes generated by JAXB) has, if it is not acceptable to use a subclass wherever its superclass is allowed. Perhaps there is some other way to do polymorphism that I'm missing?
    I really want to have a functionality such as the code example below implies. Does JAXB have the feature I'm looking for, or do I need to switch to another framework? If I need to switch, which one should I use?
    Thanks for any help that can be offered.
    schema:
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
         <xs:element name="people">
              <xs:annotation>
                   <xs:documentation>Comment describing your root element</xs:documentation>
              </xs:annotation>
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="person" type="Person" maxOccurs="unbounded"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <xs:complexType name="Person">
              <xs:sequence>
                   <xs:element name="name" type="xs:string"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="Employee">
              <xs:complexContent>
                   <xs:extension base="Person">
                        <xs:sequence>
                             <xs:element name="title" type="xs:string"/>
                        </xs:sequence>
                   </xs:extension>
              </xs:complexContent>
         </xs:complexType>
    </xs:schema>
    expected JAXB output:
    <people>
    <person>
    <name>Joe Sample</name>
    </person>
    <person>
    <name>Jane Sample Employee</name>
    </person>
    </people>
    actual JAXB output (invalid):
    <people>
    <person>
    <name>Joe Sample</name>
    </person>
    <person>
    <name>Jane Sample Employee</name>
    <title>Engineer</title>
    </person>
    </people>
    Java code:
    Person person = factory.createPerson();
    person.setName("Joe Sample");
    Employee employee = factory.createEmployee();
    employee.setName("Jane Sample Employee");
    employee.setTitle("Engineer");
    People people = factory.createPeople();
    people.getPerson().add(person);
    people.getPerson().add(employee);
    - Matt Munz

    hi Matt,
    I think your expected output may be wrong, and the actual output be correct eg consider this code:
    import java.util.*;
    class Person {
         String name;
         public String toString() { return "Person("+name+")"; } }
    class Employee extends Person {
         String title;
         public String toString() { return "Employee("+name+", "+title+")"; } }
    public class JBTest {
         public static void main(String[]arg) {
              List l = new ArrayList();
              Person p = new Person();
              p.name="Joe Sample";
              Employee q = new Employee();
              q.name="Jane Sample Employee";
              q.title="Engineer";
              l.add(p);
              l.add(q);
              System.out.println(l);
    which outputs
         [Person(Joe Sample), Employee(Jane Sample Employee, Engineer)]
    So although the List is untyped (am not keeping up with generics..
    sorry!) in the above code, even if it were a Person list it would still be legitimate to add an Employee to the list (since an Employee is-a
    Person)
    saying that, am not sure how you could achieve what you are trying? are you hoping for the object tree you construct not to be validated?
    thanks,
    asjf

  • Using a polymorphic view object with binding

    Hi,
    I'm hoping there's something simple I'm missing when trying to setup up the bindings for a ADF/struts page using a polymorphic view object.
    I'm using Entity and VO polymorphism to create a Question which has different types - boolean, multi-choice, likert, etc. I have the various question types created as sub type entity and view objects and added to the app module - when added to the app module the question types are subtypes of QuestionView so they don't actually appear in the Data Controls palette. This setup is like that used in Steve Muench's examples (blog at http://radio.weblogs.com/0118231/stories/2003/02/06/constructingTheDesiredEntityInAPolymorphicViewObject.html and the related undocumented one)
    My question is, how do I get to the data and have jdev create the necessary bindings for the extra attributes the subtype questions have? Since they don't appear as available data controls I can't create a binding iterator or anything for them - short of adding them as spearate view objects (which destroys the whole point of using polymorphism in this case) is there a way to do this?
    Really, the only reason I want to use the polymorphism is so I can have different types of entity validation depending on the type. Should I just simplify this to be one entity object with one VO and put all the validation into "if else's" based on a discriminator?
    Assistance appreciated...
    - Nathaniel

    How else are you planning to associate a JUTableBinding to the 'common' iterator containing all four types of rows and then selectively display them? Perhaps you'd need a custom model over the JUTabelModel that'd filter the rows out.
    I'm not sure if all that trouble is worth it given that your datasets (as far as mentioned in this post) are not large. If these tables/data has to be refreshed/executed a number of times, then you may see the overhead of four queries otherwise it should be fine as database is always faster in filtering rows than doing that in memory.

  • Abstract Class and polymorphism - class diagram

    Hi,
    ]Im trying to draw a class diagram for my overall system but im not too sure how to deal with classes derived from abstract classes. I'll explain my problem using the classic shape inheritance senario...
    myClass has a member of type Shape, but when the program is running shape gets instantiated to a circle, square or triangle for example -
    Shape s = new circle();
    since they are shapes. But at no stage is the class Shape instantiated.
    I then call things like s.Area();
    On my class diagram should there be any lines going from myClass directly to circle or triangle, or should a line just be joining myClass to Shape class?
    BTW - is s.Area() polymorphism?
    Thanks,
    Conor.

    Sorry, my drawing did not display very well.
    If you have MyClass, and it has a class variable of type Shape, and the class is responsible for creating MyClass, use Composition on your UML diagram to link Shape and MyClass.
    If you have MyClass, and it has a class variable of type Shape, and the class is created elsewhere, use Aggregation on your UML diagram to link Shape and MyClass.
    If you have MyClass, and it is used in method signatures, but it is not a class variable, use Depedency on your UML diagram to link Shape and MyClass. The arrow will point to Shape.
    Shape and instances of Circle, Triangle, Square, etc. will be linked using a Generalization on your UML diagram. The arrow will always point to Shape.
    Anything that is abstract (class, method, variable, etc.) should be italicized. Concrete items (same list) should be formatted normally.
    BTW, the distinction between Composition, Aggregation and Dependency will vary from project to project or class to class. It's a gray area. Just be consistent or follow whatever guidelines have been established.
    - Saish

  • Runtime Polymorphism

    Hi
    Asper the code snippet below:
    What is the advantage that we get by declaring the object as in Statement 1 over the declaration in Statement 2 below, when both obj1 and obj2 can perform all methods available in subclass B. Moreover as per what I know, obj1 can not access those methods of class B which are not available in class A whereas obj2 can perform all methods of class A as well as class B ???
    Then why do programmers use Statement type of declaration???
    Runtime polymorphism also occurs if I declare it in the Statement 2 way, the show() function as described in both classes gets overridden.
    Can anyone read the problem statement carefully and really explain me why anyone would ever want to use Statement 1 declaration when there there is no harm in Statement 2 declaration and rather an advantage that obj2 can use all the class B's functions whereas obj1 might not be able to do so? Is there anything that I am missing here?????
    Am a novice programmer, forgive me if I am missing something. Kindly clarify my doubt if you have time.
    Class A{
       void show(){
          System.out.println("Am in A");
    Class B extends A {
       void show(){
          System.out.println("Am in B.");
    Class Test{
       public static void main(String[] args){
          A obj1 = new B();  // Statement 1
          B obj2 = new B();  // Statement 2
          obj1.show();
          obj2.show();
    }

    justgig8 wrote:
    Runtime polymorphism also occurs if I declare it in the Statement 2 way, the show() function as described in both classes gets overridden.
    Can anyone read the problem statement carefully and really explain me why anyone would ever want to use Statement 1 declaration when there there is no harm in Statement 2 declaration and rather an advantage that obj2 can use all the class B's functions whereas obj1 might not be able to do so? Is there anything that I am missing here?????In your limited example, there's really no non-trivial advantage. We had a long, drawn out argument about this recently, but basically it boils down to, "in general, if possible, code to the interface (or least concrete type)". In your example, it might be that main() becomes a long, complex method, and one day somebody tells you that it would work 20 times faster if you used a (C extends A) instead of a B. If you were using the first declaration, it'd be an easy switch. If you were using the second, it might not be.
    But the real power of coding to the interface (and polymorphism in general) is for less trivial situations, where the choice of type is not fully encapsulated as it is in your example.

  • ADF BC : polymorphic activation issue

    hi
    Please consider this example application created using JDeveloper 10.1.3.4.0
    at http://www.consideringred.com/files/oracle/2010/PolymorphicActivationIssue10gApp-v0.01.zip
    It has Entity Objects AdPresEmployees and ItProgEmployees that extend the Employees Entity Object (based on HR.EMPLOYEES).
    There is also the View Object EmployeesVO that is based on Employees and its sub-types AdPresEmployees and ItProgEmployees.
    The basic scenario (sc1) for the expected behaviour goes like
    - (sc1-a) run createEmployees.jspx
    - (sc1-b) enter "20" for "create_pEmployeeId" and "20email" for "create_pEmail" and click the "createAdPresEmployees" button, resulting in a new AdPresEmployeesImpl based row in the table
    - (sc1-c) enter "21" for "create_pEmployeeId" and "21email" for "create_pEmail" and click the "createItProgEmployees" button, resulting in a new ItProgEmployeesImpl based row in the table
    To reproduce scenario (sc1) it is important to not have the system property "jbo.ampool.doampooling" configured to get the default Application Module pooling behaviour, and to have "-Ddopolymorphicactivationfix=false" (or not configured), to result in two new rows in the table as can be seen in the screenshot PAI-sc1-doPooling-noFix.png.
    To reproduce the problem in a scenario (sc2) with the same steps as (sc1) but with "-Djbo.ampool.doampooling=false" configured to avoid Application Module pooling and force passivation and activation, still "-Ddopolymorphicactivationfix=false", the result for a step (sc2-c) would be "JBO-27027: Missing mandatory attributes for a row with key ..." and several "JBO-27014: Attribute ... is required" messages as can be seen in the screenshot PAI-sc2-noPooling-noFix.png.
    Maybe the problem in scenario (sc2) is related to bug 9495116, "PROBLEM WITH ACTIVATION PASSIVATION MAKING USE OF POLYMORPHISM ENTITIES ...".
    After some debugging, to try and work around this problem I have overridden the method findByPrimaryKey() in a custom Entity Definition class like this, conditionally calling findByPKExtended()
    public class EmployeesDefImpl
         extends EntityDefImpl
         public EntityImpl findByPrimaryKey(DBTransaction pDBTransaction, Key pKey)
              if ("true".equals(System.getProperty("dopolymorphicactivationfix"))
                   && isCalledFromActivateNewRowTrackerMethod())
                   return super.findByPKExtended(pDBTransaction, pKey, true);
              return super.findByPrimaryKey(pDBTransaction, pKey);
    }So, a scenario (sc3) similar to (sc1) with default Application Module pooling but with "-Ddopolymorphicactivationfix=true" still behaves the same as (sc1), resulting in two new rows in the table as can be seen in the screenshot PAI-sc3-doPooling-doFix.png.
    But, also a scenario (sc4) with "-Djbo.ampool.doampooling=false", so no pooling, and "-Ddopolymorphicactivationfix=true", now behaves as expected, see screenshot PAI-sc4-noPooling-doFix.png.
    questions:
    - (q1) Is there a real solution for the polymorphic activation problem in scenario (sc2)?
    - (q2) Is the workaround in scenario (sc4) a valid workaround, or how can it be improved?
    many thanks
    Jan Vervecken

    fyi
    This looks like it could be related to the blog post from Dimitrios Stassinopoulos, "Entity Inheritance And Passivation-Activation Possible Problem in ADF 11g ",
    at http://dstas.blogspot.com/2010/11/entity-inheritance-and-passivation.html
    regards
    Jan

  • Polymorphic question

    this is one of the questions for the java exam . i don't seem to understand the answer.
    class SuperBase
        void print (SuperBase a)
            System.out.print("Super");
    class Base extends SuperBase
        void print (Base b)
            System.out.print("Base");
    class Derived extends Base
        static void print (Derived c)
            System.out.print("Derived");
    public class Test {
        /** Creates a new instance of Test */
        public static void main (String args[])
            SuperBase a1 = new SuperBase();
            SuperBase b1 = new Base();
            Base c1 = new Derived();
            a1.print(new Base());
            b1.print(new Derived());
            c1.print(new Derived());
    }the answer to this is super super base. i compiled and checked it.
    I thought the answer would be super base base.
    since b1 is a object type base with a reference variable of type superbase when the method is called at runtime i thought it would make a Polymorphic call the base method. therefore printing base for this call b1.print(new Derived());
    I hope someone can explain why this is not the case. Thank you for your help.

    sorry sujji i still don't get it.
    i thought for example if you got a horse class which extends an animal class which both contain for example an eat method ie public void eat()
    then
    Animal a = new Animal();
    Horse b = new Horse();
    a.eat(); //runs animal version
    b.eat(); // runs horse version
    does this mean the base method is not overidding the SuperBase class print method but actually overloading it.
    void print (SuperBase a) // in SuperBase class
    void print (Base b)// in Base Class
    if thats the case i understand, otherwise i am now completely lost.

  • Plsql object type polymorphism

    Hi everyone.
    Is adhoc polymorphism possible in pl/sql using Oracle's object types? Here is some sample code that I tried on an Oracle 10.2.0.3 64-bit database running on Solaris.
    Connected.
    09:58:58 SQL> create type root_ty as object (
    09:59:03   2    a1     varchar2(32 char)
    09:59:03   3  ) not final
    09:59:03   4  /
    Type created.
    Elapsed: 00:00:00.17
    09:59:05 SQL> create type sub_ty under root_ty (
    09:59:10   2    a2     varchar2(32 char)
    09:59:10   3  , constructor function sub_ty(str in varchar2) return self as resul
    09:59:10   4  , member procedure display_a2
    09:59:10   5  ) final
    09:59:10   6  /
    Type created.
    Elapsed: 00:00:00.06
    09:59:12 SQL> create or replace type body sub_ty is
    09:59:18   2    constructor function sub_ty(str in varchar2)
    09:59:18   3      return self as result
    09:59:18   4    is
    09:59:18   5    begin
    09:59:18   6      self.a2 := str;
    09:59:18   7     
    09:59:18   8      return;
    09:59:18   9    end;
    09:59:18  10   
    09:59:18  11    member procedure display_a2
    09:59:18  12    is
    09:59:18  13    begin
    09:59:18  14      dbms_output.put_line('a2 value is .... '||a2);
    09:59:18  15    end;
    09:59:18  16  end;
    09:59:18  17  /
    Type body created.
    Elapsed: 00:00:00.04
    09:59:20 SQL> set serveroutput on
    10:00:31 SQL> declare
    10:00:35   2    l_ty    root_ty;
    10:00:35   3  begin
    10:00:35   4    l_ty := new sub_ty('Woot!');
    10:00:35   5   
    10:00:35   6    l_ty.display_a2();
    10:00:35   7  end;
    10:00:35   8  /
      l_ty.display_a2();
    ERROR at line 6:
    ORA-06550: line 6, column 8:
    PLS-00302: component 'DISPLAY_A2' must be declared
    ORA-06550: line 6, column 3:
    PL/SQL: Statement ignored
    Elapsed: 00:00:00.06
    10:00:37 SQL> declare
    10:00:53   2    l_ty    root_ty;
    10:00:53   3  begin
    10:00:53   4    l_ty := new sub_ty('Woot!');
    10:00:53   5   
    10:00:53   6  --  l_ty.display_a2();
    10:00:53   7  end;
    10:00:53   8  /
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.01
    10:00:53 SQL> declare
    10:01:30   2    l_ty    sub_ty;
    10:01:30   3  begin
    10:01:30   4    l_ty := new sub_ty('Woot!');
    10:01:30   5   
    10:01:30   6    l_ty.display_a2();
    10:01:30   7  end;
    10:01:30   8  /
    a2 value is .... Woot!
    PL/SQL procedure successfully completed.Certainly seems like this should be possible ... Am I missing something simple?
    Thanks for any input.
    - KR

    Here is an example of what polymorphism is supposed to do:
    SQL> create type bird as object
      2  (name varchar2 (30)
      3  , member function fly return varchar2
      4  , member function make_a_noise return varchar2)
      5  not final
      6  /
    Type created.
    SQL>
    SQL> create type birds_nt as table of bird;
      2  /
    Type created.
    SQL>
    SQL>
    SQL> create or replace type body bird as
      2
      3      member function fly return varchar2
      4      is
      5      begin
      6          return 'my name is '||self.name;
      7      end;
      8
      9      member function make_a_noise return varchar2
    10      is
    11      begin
    12          return 'generic twitter';
    13      end;
    14
    15  end;
    16  /
    Type body created.
    SQL>
    SQL>
    SQL> create type duck under bird (
      2  overriding member function make_a_noise return varchar2
      3  , member procedure waddle
      4  );
      5  /
    Type created.
    SQL>
    SQL> create or replace type body duck as
      2
      3
      4      overriding member function make_a_noise return varchar2
      5      is
      6      begin
      7          return 'quack!';
      8      end;
      9
    10      member procedure waddle
    11      is
    12      begin
    13          null;
    14      end;
    15
    16
    17  end;
    18  /
    Type body created.
    SQL>
    SQL>
    SQL>
    SQL> create type chicken under bird (
      2  overriding member function make_a_noise return varchar2
      3  , member procedure peck
      4  )
      5  not final;
      6  /
    Type created.
    SQL>
    SQL> create or replace type body chicken as
      2
      3
      4      overriding member function make_a_noise return varchar2
      5      is
      6      begin
      7          return 'cluck!';
      8      end;
      9
    10      member procedure peck
    11      is
    12      begin
    13          null;
    14      end;
    15
    16
    17  end;
    18  /
    Type body created.
    SQL>
    SQL> create type canary under bird (
      2  overriding member function make_a_noise return varchar2
      3  );
      4  /
    Type created.
    SQL>
    SQL> create or replace type body canary as
      2
      3
      4      overriding member function make_a_noise return varchar2
      5      is
      6      begin
      7          return 'I taught I taw a puddy tat!!!';
      8      end;
      9
    10
    11  end;
    12  /
    Type body created.
    SQL>
    SQL> create type rooster  under chicken (
      2  overriding member function make_a_noise return varchar2
      3  )
      4  ;
      5  /
    Type created.
    SQL>
    SQL> create or replace type body rooster as
      2
      3
      4      overriding member function make_a_noise return varchar2
      5      is
      6      begin
      7          return 'That''s a joke... I say, that''s a joke, son.';
      8      end;
      9
    10
    11  end;
    12  /
    Type body created.
    SQL>
    SQL>
    SQL>
    SQL>
    SQL> declare
      2      my_aviary birds_nt := birds_nt();
      3  begin
      4      my_aviary.extend(5);
      5      my_aviary(1) := duck('Donald');
      6      my_aviary(2) := chicken('Chicken Little');
      7      my_aviary(3) := canary('Tweetie Pie');
      8      my_aviary(4) := rooster('Foghorn Leghorn');
      9      my_aviary(5) := bird('?');
    10      for idx in my_aviary.first()..my_aviary.last()
    11      loop
    12          dbms_output.put_line( my_aviary(idx).fly() );
    13          dbms_output.put_line( my_aviary(idx).make_a_noise() );
    14      end loop;
    15  end;
    16  /
    my name is Donald
    quack!
    my name is Chicken Little
    cluck!
    my name is Tweetie Pie
    I taught I taw a puddy tat!!!
    my name is Foghorn Leghorn
    That's a joke... I say, that's a joke, son.
    my name is ?
    generic twitter
    PL/SQL procedure successfully completed.
    SQL>Now, in that loop woudl it make sense to execute a peck() on all of those entries? Nope. Furthermore as far as I can tell it is not possible to find out what sub-type an object is from with PL/SQL, so you couldn't even use Padders's TREAT ploy.
    So: if you want to do something generic use a super-type. If you want to do something specific use a sub-type.
    Cheers, APC
    blog: http://radiofreetooting.blogspot.com

Maybe you are looking for

  • Patch compliance report for all machines in collection

    Good day to all, We are trying to create a report in SCCM 2012 that will show us all missing updates on all computers in collection. But we would like to display in this report only patches which are really targeted to the machines in collection. Let

  • Cost of good sold (COGS) in planning

    Hi, Can someone please guide me how to estimate COGS for a product? Thank you

  • Can I make an older iMac go wireless?

    I recently was given an older iMac for my 6 yr. old daughter. It does have OSX. However, I am not very apple savy & and I was told that they do not sell the airport for the older models @ the apple store. Our house is wireless. Does anyone have any s

  • Proc*c error in linux

    I have some pro*c reports. When i compile them,i get the error: cc:paidgis.pc.c: No such file or directory cc:paidgis.pc.o: No such file or directory strip: paidgis.pc: File format not recognised, I am on linux RH 7.2 and oracle 9.0.0.1 The proc/c++

  • Support for Windows CE devices with StrongArm

    Will there be support for the Windows CE devices with the StrongArm processor (like the Compaq iPaq) in Oracle Lite? Peter Bakker