Вы находитесь на странице: 1из 3

Test Two Preparation Questions 1. Explain the concept of polymorphism to a functional programmer unfamilar with Object Oriented development.

Explain how it allows the programmer to program in the general rather than the specific and why this is useful. Polymorphism comes from the word poly which means many and morph which means changing forms. Polymorphism in coding is using the same interface to provide to different entities at a time. Polymorphism allows the programmer to program in general because polymorphism allows code reusability. 2. Within the context of OO explain the meaning of inheritance !nheritance is a concept in which a class shares the attributes and methods with another class. !t usually involves a parent class and a child class in which the child class will inherit the parent class"s attributes and methods which allows code reusability in object oriented concepts.

#. $ow does inheritance promote reusability% !nheritance promotes reusability by allowing the child class to inherit attributes and methods from the parent class. &. Explain the different types of relationships between classes !nheritance !nheritance is a type of relationship in which the child class will inherit the parent classes" attributes and methods. !nheritances uses 'is a( concept in relating different classes. )or example a student is a person. !n this case the student inherits the person"s class. *ggregation *ggregation is a type of relationship which is optional+based. )or instance when the parent class is destroyed the child class will not be affected. *ggregation uses a 'has a( concept in relating different classes. )or instance a car has an engine. When the parent class which is car is destroyed the engine class still remains intact. ,he level of relationship is average in aggregation. -omposition -omposition is a type of relationship which is mandatory+based. )or instance when the parent class is destroyed the child class is also affected. -omposition also uses a 'has a( concept in relating different classes as similar to aggregation but composition does not allow the child class to exist without the parent class. )or example a department has a staff. When the department class is destroyed the staff class do not exist. ,he level of relationship is high in composition.

*ssociation *ssociation is a type of relationship in which classes associate or are lin.ed with each other. *ssociation also uses a 'has a( concept in relating different classes but association differs from aggregation and composition because association is just a structural relationship. )or example a course has a lecturer. /. Explain protected member access Protected member access is a type of class declaration in which are only accessible to members within the class. Protected member access differs from public access and private access by allowing the specific members within the class only to access the variables and methods in it whereas private access allows other classes to access the class provided the class is lin.ed through struct or within the same class while public access allows anyone to use the class as long as they are lin.ed. 0. 1iscuss the ways in which inheritance promotes software reuse saves time during program development and helps prevent errors !nheritance promotes software reusability by inheriting the parent"s class attributes and methods so that the programmer does not need to retype the same code over again. !nheritance also saves time during program development by reducing the time needed to debug and compile the code due to less coding and inheritance also helps to prevent errors by reducing the amount of code the programmer needs to type which results in easier error identification. 2. Explain why multiple inheritance is not possible in 3ava and how this can be overcome 4ultiple inheritance is not possible in 3ava because multiple inheritance complicates the design and creates problem during casting chaining etc. 5esides that multiple inheritance causes ambiguity which results in a diamond formation in class diagrams whereby two child classes will inherit from one parent class and one new child class will inherit from those 2 previous child class 6now called parent class7. 4ultiple inheritance can be overcome by using interfaces in java. 5esides that the programmer is able to use delegations which stimulate multiple inheritance in java. 8. $ow does polymorphism promote extensibility% Polymorphism promotes extensibility by ma.ing all method calls generic. When a new class type with the appropriate method is added to the hierarchy no changes needed to be made in the generic method calls. 9. $ow does polymorphism enable you to program :in the general: rather than :in the specific:% 1iscuss the .ey advantages of programming :in the general. Polymorphism enables the programmer to concentrate on the processing of common operations which are applied to all data types in the system without going into

individual details of each data types. ,he general processing capabilities are separated from the internal details of each data type. 1;. 1iscuss the concept of casting and how it relates to polymorphism -asting is a process in java where a type of variable or expression is converted into another type as long as the conversion ma.es sense. -asting is related to polymorphism because casting converts a variable into another type which in fact the variable 'morphs( into another variable.

Вам также может понравиться