• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

UML Test questions

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everyone!
Can anyone tell me answers to these dicy questions from IBM486 Sample test
1.A resulting benefit of using polymorphism is reduction of:

a) methods in the associated classes

b) subclasses needed to accomplish the same functionality

c) case statements and conditionals

d) coupling between classes in the system

2. UML interfaces are used to:

a) define an API for all classes.

b) program in Java, but not in C++ or Smalltalk.

c) define executable logic to reuse across classes.

d) specify required services for types of objects.
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1 = a
2 = d
I think...
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My $0.02:
1. You don't reduce the number of methods in related classes (choice a) because each class will have it's own version of the polymorphic method. (b) doesn't make sense because each subclass could potentially implement the functionality a different way and you can create as many subclasses as you like with the same method name. I can't find any reason for selecting (d) either.
Therefore, (c) seems to be the best choice for me. If you didn't have polymorphism, then you'd have to resort to something like:

2. (a) seems to be the best answer to me.
(b) is incorrect since the UML is not language-specific
(c) an interface does not define executable logic
(d) just doesn't sound right to me.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well my choices are
1.c
2.c
but these are really tricky questions. You get different answers everytime you think.
Is anyone sure
 
Jack Majad
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well my choices are
1.c
2.c
but these are really tricky questions. You get different answers everytime you think.
Is anyone sure
 
Jack Majad
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well my choices are
1.c
2.c
but these are really tricky questions. You get different answers everytime you think.
Is anyone sure
 
Ranch Hand
Posts: 350
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my choices are
1.c (same reason as JUNILU LACAR)
2.d
Since an interface defines just the type of service given and not how the service is to be given, I am sticking with 2.d , an Interface is something like; I press a button to get the coffee from the coffee machine ..but I DO NOT go into the exact working of how the machine is going to make my coffee, simalrly the button in the coffee machine is my interface for getting me coffee.
The examlple may b real stupid ...but I cant help it I am having Coffee rit now :-)

[This message has been edited by Vivek Viswanathan (edited March 04, 2001).]
 
Geoff Tate
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The reason I said a for no 1 is that there only has to be one method created (ie. parentclass.move()) then there can me a subclass.move(). There doesn't have to be a subclass.subclassMove(). So now I can make parentclass = subclass and call parentClass.move() and get the subclass functionality. I think I didn't select case statements and conditionals is because case statements only work with int-compatable and I think it would be tough to decide which objects method called based on an int flag if you are going to indentify objects on the fly unless you are going to do if instanceOf == object1 { oType = 1 }, then test oType. I could be and have been wrong before though.
 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is an old POST. But anyone who is sure about the answer? I got problems with the same two questions too.
 
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. c
Polymorphism is used to reduce case and conditions.
2. d
c is a bit tricky.Interface allows reuse, but doesn't have executable logic.
-- Sandeep
 
Caroline Iux
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks! I assume "executable logic" means the implementation of an operation here.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Answer for Q No 1 : a
According to UML User Guide by Booch, Jacobson and Rumbaugh the first choice is the most suitable one for the usage of Polymorphism
Answer for Q No 2 : d
According to the same reference an Interface is defined like this option (d). I feel very sorry for those who have chosen wrong answers. I just want to tell them one thing : PLEASE STRENGTHEN YOUR FUNDAS ON UML. Refer to standard books like User Guide. I think UMLUG is one of the very few books which provides fundamental understanding of UML concepts

------------------
Ram
 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Feel sorry for yourself and your own "FUNDAS", dude. Polymorphism and UML have nothing at all to do with each other. And just because "UML" is in the question doesn't mean that it has anything to do with the concept of "interfaces".
[This message has been edited by JUNILU LACAR (edited June 08, 2001).]
 
Desai Sandeep
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sreeram,


Originally posted by sreeram upendran:
Answer for Q No 1 : a
According to UML User Guide by Booch, Jacobson and Rumbaugh the first choice is the most suitable one for the usage of Polymorphism


I am not sure on your reasoning of how Polymorphism would reduce methods in associated classes.With polymorphism you can override methods (or in UML terms, should I say operations) defined in your supertype.If you have 10 subtypes of a supertype and if you have 10 different implementations for your operations (assuming that each subtype is disjoint and behaves/reacts/operates in a different manner; that is reason which prompted you to create a subtype), you will have 10 different implementations of the operation,(i.e. different methods for each of the 10 subclasses for the operation defined in your supertype!).So how is polymorphism reducing methods in the associated classes?
The correct answer for 1. should be C.Polymorphism allows you to reduce case and conditions.
To illustrate this further, let us assume you have an [b]execute()
method in your superclass, Payment.The client is interested in 3 kinds of Payment - Cash,Credit and Check.Without subclassing Payment (and hence not overriding the execute() operation), you would need to put the conditional logic (switch..case,if..else) in the Payment class to account for these kinds of payment.This is so because the execute() would have to take care of all the three kinds of Payment.If you override execute() in your subclasses, viz., CashPayment,CreditPayment and CheckPayment then you only have to plug in a different subclass object to the superclass reference to call the required execute() method.This means the conditional logic in the superclass is no longer required, as the overidden execute() method is taking care of the different kinds of payments.


Originally posted by sreeram upendran:
Answer for Q No 2 : d


Your answer for 2. is correct!
Would like to say though, UML Interfaces are not Java Interfaces.They symbolize responsibilities (services/operations), which the derived specialized concepts (subtypes) must conform to.UML Interfaces may be implemented as a normal Java class or an interface or an abstract class in the Construct phase, as long as it conforms to the responsibilities specified for it.
Hope this helps,
Sandeep
[This message has been edited by Desai Sandeep (edited June 09, 2001).]
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by sudharma malkas:
Hello Everyone!
Can anyone tell me answers to these dicy questions from IBM486 Sample test
1.A resulting benefit of using polymorphism is reduction of:

a) methods in the associated classes

b) subclasses needed to accomplish the same functionality

c) case statements and conditionals

d) coupling between classes in the system

2. UML interfaces are used to:

a) define an API for all classes.

b) program in Java, but not in C++ or Smalltalk.

c) define executable logic to reuse across classes.

d) specify required services for types of objects.


The correct answers are 1-c, 2-d. I have scored 100 on the test a couple of times so I am positive, besides both these answers make sense.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Correct answers are
1. c
2. d
I am 100% sure about these answers.
Tariq
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the confusion about question 1 has to do with inheritance vs. polymorphism.
Inheritance eliminates the need to duplicate method implementations in subclasses.
Polymorphism eliminates the need to write conditional logic. The appropriate method implementations are determined at runtime through dynamic binding.
Hope this is helpful,
Joe
 
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
My answers for these two questions are
1) c
2) d
When u r using Polymorphisam then via dymanic binding the references are assigned appropriate objects at run time so their is no need to check to what Class an instance belongs!
As the case of interaces, i think that interfaces just declare what services are required from an object. So any class which is realizing an interface has to provide the complete Services that the interface declares.
Hope this helps!


 
Desai Sandeep
Ranch Hand
Posts: 1157
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Joe,

Originally posted by Joe Rossano:
Inheritance eliminates the need to duplicate method implementations in subclasses.


I would say Inheritance allows you to define a generic operation in the superclass.The implementation of this operation is taken care of by methods defined in the subclasses.
I am not sure, if we could say Inheritance eliminates the duplicate method implementation in the subclasses since each subclass is going to have its own specialized implementation.However, the subclass would inherit the responsibility defined in the superclass.
Hope this helps,
Sandeep
 
She's brilliant. She can see what can be and is not limited to what is. And she knows this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic