1. Define the Following OO Terms and How They Relate to Each Other
Total Page:16
File Type:pdf, Size:1020Kb
1. Define the following OO terms and how they relate to each other Class, Object, Method
A class is a description of what the objects produced from the class will look like. A class is usually comprised of variable and method definitions. An object is an instance of a class. It is the most basic element in OO design. A method is a “behavior” that describes what an object can do. A method receives messages and performs a set of operations – usually on the object the method is contained in.
2. Describe inheritance and polymorphism as it applies to OO design Give a real world example of when you would use inheritance that we haven't used in class.
Inheritance is the term used to describe the relationship between general categories and more specific categories. In Java, inheritance is a mechanism that enables one class to inherit both behavior and attributes from another class. A good example of inheritance is the relationship between Motor Vehicles and Cars and Boats. Cars and Boats are both more specific types of the general category Motor Vehicles. In this example Motor Vehicles is a superclass and Cars and Boats are subclasses.
Polymorphism technically means “many forms”. It refers to the way different objects can respond in their own way to the same message. For example, different objects of type Birds, Dogs and Cats can receive the message Speak. The Bird object will respond “Tweet”, the Dog object will respond “Woof”, and the Cat object will respond “Meow”.
3. What does encapsulation mean and what are its benefits?
Encapsulation means that an object has attributes and methods combined into one unit. This means that you do not need to know the internal structure of the object to send messages to it. You only need to know what an object can do for you. Encapsulation hides the internal structure of objects, also protecting them from corruption.