StudentShare
Contact Us
Sign In / Sign Up for FREE
Search
Go to advanced search...
Free

Inheritance Information Technology - Assignment Example

Cite this document
Summary
Inheritance One of the major tenets of Object-Oriented programming is promotion of code re-use. Most objects in real life have certain things in common for example a car, a truck and a motorcycle are all vehicles but with different distinguishing features such as size, wheels and maximum speed…
Download full paper File format: .doc, available for editing
GRAB THE BEST PAPER91.3% of users find it useful
Inheritance Information Technology Assignment
Read Text Preview

Extract of sample "Inheritance Information Technology"

Inheritance One of the major tenets of Object-Oriented programming is promotion of re-use. Most objects in real life have certain things in common for example a car, a truck and a motorcycle are all vehicles but with different distinguishing features such as size, wheels and maximum speed. In object-oriented program a good design practice calls for creation of fairly generic version of a class. The programmer then uses these generic classes to build up specialized classes. This is achieved through inheritance.

Oracle (2012) defines inheritance as that ability of a class to inherit commonly used structure and behavior from another class. Continuing with the vehicle example it is clear that cars, trucks and motorcycles all have engines, wheels, shape, speed and other attributes which are expected of all vehicles. The subclass inherits from the superclass (Eck, 2011). In C++, the subclass is also referred to as the derived class or child class while the superclass is the base class or parent class.

In Java, a class arrow points toward the class from which it extends. An example is shown in the diagram below. In object-oriented program class inheritance and interface implementation are used to manifest the concept of IS-A relationship. An IS-A relationship states that this item is a type of that item (Sierra & Bates, 2005). Using our example one can correctly say a car IS-A vehicle or a truck IS-A vehicle. In Java this unique relationship, IS-A relationship, is expressed through class inheritance and interfaces.

To show inheritance the keyword extends is used whereas to show interface implementation the keyword implements is used. This is demonstrated below: class Vehicle { public void displayVehicle() { System.out.println(“displaying vehicle”); } // additional code } // end Vehicle class Car extends Vehicle { int numberOfDoors; } // more code }// end Car class Motorcycle extends Vehicle { int numberOfWheels; } // more code }// end Motorcycle class Truck extends Vehicle { int numberOfAxles; } // more code }// end Truck public class TestVehicles { public static void main (String[ ] args) { Car ferrari = new Car(); ferrari.

displayVehicle(); ferrari.numberOfDoors(); }//end main }//end TestVehicles In the example above we see the element of code re-use where a program could refer to ferrari.numberOfDoors, an member variable of the Car class as well ferrari.displayVehicle() a method it inherits from the class Vehicle. In the above example the method displayVehicle() could be applied to a wide range of different kinds of vehicles without it having to be re-implemented. This means that all subclasses of Vehicle are guaranteed to have the behavior of their superclass Vehicle (Weiss, 2006).

The second purpose of inheritance is to allow for classes to be accessed polymorphically. Suppose at the time of writing the Vehicle class, the programmer has no idea of the different forms of vehicles that could be written by any other programmer. However you may want a certain program that you write now to be able to call a method from any class that extends the Vehicle class. Polymorphism allows us to treat any subclass of Vehicle as a Vehicle. This means that the programmer can call, in our example the method displayVehicle() from any object that inherits / extends the class Vehicle.

An example of using inheritance to allow for polymorphism of classes is shown below: class Vehicle { public void displayVehicle() { System.out.println(“displaying vehicle”); } // more code } // end Vehicle class Car extends Vehicle { int numberOfDoors; } // more code }// end Car class Motorcycle extends Vehicle { int numberOfWheels; } // more code }// end Motorcycle Now imagine a test class has a method with a declared argument type of Vehicle. This means any subclass of Vehicle can be passed to the method with argument of type Vehicle.

This code is shown below: public class TestVehicles { public static void main (String[ ] args) { Car ferrari = new Car(); Motorcycle Honda = new Motorcycle(); showVehicle(ferrari); //output is displaying vehicle showVehicle(honda); //output is displaying vehicle }//end main public static void showVehicle(Vehicle vessel){ vessel.displayVehicle(); } }//end TestVehicles The output from the above code is the same. The important point to note is that the methods called on a reference are totally dependent on the declared type of the variable, no matter what the actual object is, that the reference is referring to (Sierra & Bates, 2008).

There is one major difference of inheritance between Java and other programming languages such as C++. In Java, a class cannot inherit more than one class. In C++ a class can have multiple inheritances. For example in C++ class A can extend B and C at the same time as shown below class A extends B, C { // more code } // this is not possible in Java Java prohibits this because of the so called” Deadly Diamond of Death”. In the diagram shown below suppose Vessel extends Car and Motorcycle each of which has a start() method which of these versions will the Vessel subclass inherit?

References Eck, D. J. (2011). Introduction to Programming Using Java, Version 6.0. Retrieved from http://math.hws.edu/javanotes/ Oracle. (2012). What Is Inheritance? The JavaTM Tutorials. Retrieved August 8, 2012, from http://docs.oracle.com/javase/tutorial/java/concepts/inheritance.html Sierra, K., & Bates, B. (2005). Head First Java (2nd ed.). Sebastopol, CA: O’Reilly Media, Inc. Sierra, K., & Bates, B. (2008). SCJP Sun Certified Programmer for Java 6 Study Guide Exam (310-065). New York: McGraw-Hill. Weiss, M. A. (2006). Data Structures & Problem Solving Using Java (3rd ed.). Boston, MA: Pearson Education. 

Read More
Cite this document
  • APA
  • MLA
  • CHICAGO
(“Inheritance Information Technology Assignment Example | Topics and Well Written Essays - 750 words”, n.d.)
Inheritance Information Technology Assignment Example | Topics and Well Written Essays - 750 words. Retrieved from https://studentshare.org/information-technology/1455660-inheritance
(Inheritance Information Technology Assignment Example | Topics and Well Written Essays - 750 Words)
Inheritance Information Technology Assignment Example | Topics and Well Written Essays - 750 Words. https://studentshare.org/information-technology/1455660-inheritance.
“Inheritance Information Technology Assignment Example | Topics and Well Written Essays - 750 Words”, n.d. https://studentshare.org/information-technology/1455660-inheritance.
  • Cited: 0 times

CHECK THESE SAMPLES OF Inheritance Information Technology Assignment

Management and Modeling of Oracle Data Modeler

Moreover, it is not dependent on any specific technology of data management.... Platinum technology later purchased it in 1998.... Erwin can be used to perform data modeling for different types of databases like information systems, database transactional systems, data marts, and several others.... For instance, it allows for viewing and manipulation of information engineering diagrams accompanied by notations....
12 Pages (3000 words) Assignment

Personal Perception of Information Technology

hellip; I use cell phone, computer, internet and software programs in the lieu of information technology.... The movie that I have selected for the review of information technology is “GoldenEye”.... It is one among the James Bond series and uses a lot of information technology such as computer systems, emailing, data management, information retrieval, online data access, digital photography and much more.... The paper states that the technology that is used nowadays is  communicating and linking people together, global linkage is created with the help of websites dealing with online businesses, cell phones and other communicating devices such as fax machines, pagers and many other tools are used....
6 Pages (1500 words) Assignment

Product and Market Strategies in Relation to Research Development Program

technology management is a fundamental aspect in offsetting the risks of new technology and at the same time acquiring the operational benefits that come along with a properly managed technology.... Managing a new technology needs a thorough knowledge of business technology… In addition, the managers should understand the best ways of achieving efficiency internally through applying new technology....
5 Pages (1250 words) Assignment

Reflective Report- Oticon the disorganised organisation

In order for a company to exist in the highly competitive global market, it is critical to conduct a This research enabled Oticon to keep up with the pace of technology, as well as recognize customer's demands and make the correct adjustments where required (Perlitz 2007, p.... In addition, the essay will provide the description of the organization and industry in which the change happened, and the particular information.... This case study's information is obtained from the annual records of the Oticon company and personal conversation with Lars Kolind the initiator of spaghetti organization between the year 2010 and 2011 (Cattani 2011, p....
20 Pages (5000 words) Assignment

Land Law and Human Rights

The paper "Land Law and Human Rights" highlights that unity of possession requires that each co-owner be entitled to possession of the whole and the possession requirement distinguishes legal co-ownership from separate ownership of parts of the land.... nbsp;… The lack of clarity and dependency on ad hoc judicial decisions is undesirable in addressing the right to privacy and the interpretation of Article 8 has been disappointing in clarifying the legal parameters of privacy protection in the UK....
29 Pages (7250 words) Assignment

Instruction Manual Promotional Media

In Win, when both explicit and inherited ACEs are applied to an object, explicit ACEs are checked before the inherited ACEs; access is allowed or denied by the explicit even if the obverse is the case by inheritance.... This assignment considers instruction manual promotional media – branding, print, Web, TV video etc....
13 Pages (3250 words) Assignment

Legal Advices Concerning Inheritance Law

About the other, we do not have any information as you have given him up for adoption.... The author of the present assignment "Legal Advice Concerning inheritance Law" analyzes the case of Juliet and her inquiry into inheritance law.... Reportedly, there are some scenarios upon which Juliet could seek the author's advice....
10 Pages (2500 words) Assignment

Enterprise Project Management

By IT PMO charter collaborating, the company's IT directors in managing IT project portfolio helps in the development and articulation of the company's technology strategy (Mahnic, & Zabkar, 2012).... From the paper "Enterprise Project Management" it is clear that Fulgham made the big shift is a strategy by deciding in September 2010 to fight for project control from Lockheed Martin as the prime contractor and to accelerate software deliverables by the use of agile development....
7 Pages (1750 words) Assignment
sponsored ads
We use cookies to create the best experience for you. Keep on browsing if you are OK with that, or find out how to manage cookies.
Contact Us