• 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

Object Orientation

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

http://uk.sun.com/training/certification/assessment/055-Jintro.jsp



class One {
private int x;
int getX() { return x; }
}

class Two {
private int y;
public void setY(One o) {
y = o.getX();
}
}

Which is true?

These classes are NOT coupled.
These classes are loosely coupled.
These classes are tightly coupled.
These classes are abstractly coupled.


Q:Which is true?

Has-a relationships must be tightly coupled.
Is-a relationships must be well encapsulated.
Is-a relationships can be represented by using reference variables as local variables.
Has-a relationships can be represented by using reference variables as local variables.
Has-a relationships can be represented by using reference variables as instance variables.

Please Explain me the answers as i am confused in this kind of questions.
Thanking You
 
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the first example, I think the classes are loosely coupled. That's because the second class doesn't rely on the implementation of the first class. The programmer/s of the first class can change the implementation of getX() (for example, in order to return a random integer within a range) without breaking the code of the second class.

For the second example:
Has-a relationships must be tightly coupled.
(False, as long as you use the API of the classes for the objects you have.)
Is-a relationships must be well encapsulated.
(False, the question doesn't make any sense.)
Is-a relationships can be represented by using reference variables as local variables.
(False, Is-A is about inheritance.)
Has-a relationships can be represented by using reference variables as local variables.
(False, local variables don't have anything to do with it. Local variables live inside methods.)
Has-a relationships can be represented by using reference variables as instance variables.
(True, if class A Has-A B this means that class A has a reference of type B.)
 
aruna dabas
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ruben.
 
Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Whilst Reuben is right, I think, you should seek more information yourself. The Ranch encourages posters not to answer questions outright but to aid in seeking further information. Giving someone the answer does not truly help to understand an issue outright.

 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought I was explaining in enough detail the rationale to my answers, and it's not the first time coupling has come up in the forum either. Is there anything else that either Aruna or Stephen (or anyone else in the forum for that matter) would like to discuss about it? Also, how do you think I could have phrased my answers better?
 
reply
    Bookmark Topic Watch Topic
  • New Topic