CS1: Lab4

advertisement
CS1: Lab4
Be clear in your responses. Avoid 2 – 3 word sentences. Do not copy
answers from others, that will get you a zero. This is open book, open
notes and you can look for answers online as well as in your notes.
1. What is object oriented programming (OOP) ? How is it different from the linear
method?
2. What are some of the ways that OOP is superior to linear design?
3. Carefully define data encapsulation. Tell me what it is and how it relates to OOP?
4. Carefully define information hiding. Tell me how it is related to data encapsulation.
5. What reserved word do we use to create an object in Java?
6. Declare a class called Games with the following data types: double cost, String name.
7. Declare an instance of this class in void main.
8. Assign values to both cost and name. Use the code from above as your class
initialization.
9. What is the difference between a public and private variable?
10. What is a static variable and how does it work?
11. What is a final variable and how does it work?
12. Create a class Cars with the following data type: static double cost
13. Create a method called Value that takes an integer as a parameter and returns an integer
as a return type. This method will take cost and set it equal to the parameter passed and
return the value.
14. Declare an instance of this class in void main. Call method Value and pass 5 to it as its
parameter.
15. Declare another instance of this class in void main. What do you think is the value of
cost in this method? Why do you think that is the case?
Download