Java Code and Principles of Inheritence
Not what you're looking for?
Described below are three classes, Building, Hotel and Home with their respective attributes:
Building: no_of_floors, age, parking_space, size
Hotel: number_of_guests, number_of_rooms, vacancy, no_of_floors, age, parking_space, size
Home: No_of_bedrooms, no_of_occupants, finished_basement, no_of_floors, parking_space, age, size
Questions 1 through 5 are based on the classes described above:
1. Write a declaration for all three classes using the principles of inheritence. Make the Building class abstract
2. Which of the following statements is incorrect:
a. Hotel h = new Hotel();
b. Home m = new Home();
c. Building b = new Building();
3. Do Hotel and Building have an "Is A" relationship or "Has A" relationship?
4. Which of the following is true:
a. Hotel and Home are subclasses of Building
b. Hotel is a subclass of Building, Home is a subclass of Hotel.
c. Home, Hotel and Building are independent classes
d. Hotel and Home are containment classes of Building
5. If Hotel were a subclass of Building, how would you access the size attribute of Building:
a. Hotel h = new Hotel();
h.new Building();
h.size = 5;
b. Hotel h = new Hotel();
h.Building.size = 5;
c. Hotel h = new Hotel();
h.size=5;
Purchase this Solution
Solution Summary
The solution discusses the java code and principles of inheritence.
Solution Preview
This problem deals with the concept of inheritance, the capacity of a class to use the properties (variables) and methods (procedures) of another class. I used the following website as a reminder and example of how inheritance works.
http://home.cogeco.ca/~ve3ll/jatutor5.htm
The problem states as follows (restated and reformatted for readability):
Described below are three classes, Building, Hotel and Home with their respective attributes:
Building:
no_of_floors
age
parking_space
size
Hotel
number_of_guests
number_of_rooms
vacancy
no_of_floors
age
parking_space
size
Home
No_of_bedrooms
no_of_occupants
finished_basement
no_of_floors
parking_space
age
size
You will notice that the last four properties for Home and Hotel are the same as those found in Building. That is because Hotel and Home are buildings themselves. Rather than to define the properties in Hotel and Home separately, a programmer can include them using inheritance. It is less work to do so at the beginning of the program design stage, and allows for easy modification later. If a new property of Building is created that applies to all buildings (such as color or inspection history), it is better to add it as a property of building, rather than to add it separately to every different type of building. In this case, there are only Hotels and Homes, but there would be many other ...
Purchase this Solution
Free BrainMass Quizzes
Word 2010: Table of Contents
Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.
Javscript Basics
Quiz on basics of javascript programming language.
Inserting and deleting in a linked list
This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.
C++ Operators
This quiz tests a student's knowledge about C++ operators.
Basic Networking Questions
This quiz consists of some basic networking questions.