Quiz on Chapter 5 | Introduction to Programming Using Java

Quiz on Chapter 5 | Introduction to Programming Using Java

 

Quiz on Chapter 5

 

java 1 Quiz on Chapter 5 | Introduction to Programming Using Java

 

 

1. Object-oriented programming uses classes and objects. What are classes and what are objects? What is the relationship between classes and objects?

2. What are instance variables and instance methods?

3. Explain carefully what null means in Java, and why this special value is necessary.

4. What is a constructor? What is the purpose of a constructor in a class?

5. Suppose that Kumquat is the name of a class and that fruit is a variable of type Kumquat. What is the meaning of the statement “fruit = new Kumquat();”? That is, what does the computer do when it executes this statement? (Try to give a complete answer. The computer does several things.)

6. What is meant by the terms instance variable and instance method?

7. Explain what is meant by the terms subclass and superclass.

8. Modify the following class so that the two instance variables are private and there is a getter method and a setter method for each instance variable:

 

Quiz on Chapter 5 | Introduction to Programming Using Java

 

9. Explain why the class Player that is defined in the previous question has an instance method named toString(), even though no definition of this method appears in the definition of the class.

10. Explain the term polymorphism.

11. Java uses “garbage collection” for memory management. Explain what is meant here by garbage collection. What is the alternative to garbage collection?

12. What is an abstract class, and how can you recognize an abstract class in Java.

13. What is this?

14. For this problem, you should write a very simple but complete class. The class represents a counter that counts 0, 1, 2, 3, 4, …. The name of the class should be Counter. It has one private instance variable representing the value of the counter. It has two instance methods: increment() adds one to the counter value, and getValue() returns the current counter value. Write a complete definition for the class, Counter.

15. This problem uses the Counter class from the previous question. The following program segment is meant to simulate tossing a coin 100 times. It should use two Counter objects, headCount and tailCount, to count the number of heads and the number of tails. Fill in the blanks so that it will do so:

 

quiz on chapter 5

 

Quiz on Chapter 5 | Introduction to Programming Using Java

 

 

 

 

Read More…

Introduction to Programming Using Java – David J. Eck

Chapter 5.2.2 – Constructors | Introduction to Programming Using Java

Chapter 5.5.3 – Example: Vehicles | Introduction to Programming Using Java

Chapter 5.6 – This and Super | Introduction to Programming Using Java

Chapter 5.7 – Interfaces | Introduction to Programming Using Java

Chapter 5.8 – Nested Classes | Introduction to Programming Using Java

1 thought on “Quiz on Chapter 5 | Introduction to Programming Using Java”

Leave a Comment