Object-Oriented Programming Review Questions
Below are three lists of questions.
If you have successfully completed an introductory programming course (e.g. CSCI 225)
you should be able to answer all of the questions in the first list and most of those in the second list.
You may or may not be able to answer the questions in the third list.
It is important that you have a clear understanding of all of the questions in the first two lists.
Therefore, as we discuss each question please ask if you are unclear about anything.
Many of the questions are generic in the sense that they relate to Object-Oriented Programming
(OOP) in general, but some of them are specific to Java. It is absolutely critical that
you understand the difference between general concepts and language specific ones.
In fact, much of what you learned in CSCI 225 (or another programming course)
and what you will learn in this class are applicable to many other languages, including C, C++,
Pascal, scripting languages like PHP and ASP, etc.
In other words, you are not simply learning about how to program in Java, but how think computationally.
When you realize this, learning new programming paradigms and languages will be much easier.
At the end of our review discussion, you should be able to answer all of the questions in the first two lists
and know whether or not the subject of each question is related only to
Java or to OOP in general.
For Java related questions,
you should have a vague idea of how the answer might be different for
other OOP languages (like C++).
The point of the review is not to see how
smart (or dumb) anyone is, but to make sure we are all starting the course with the
same understanding. It is better to confess your ignorance about these issues now
than to be confused throughout this and the remainder of your courses.
- Basic Object-Oriented Programming
These questions are related to the material from Chapters 1-7 of the
Objects First with Java (OFWJ) textbook, although I have included some terms which
may not occur in that textbook but are commonly used.
You should be able to answer most of these, although you may need to do a little reviewing.
Do not feel bad if there are questions you do not know the answer to,
but make sure that you can answer all of them by the end of the second week of class.
- What is a class? What is an object?
What is the difference between an object and a class?
- Where do objects come from (how do you create one)?
- How many objects of a given class can you have at a given time?
- What is a data type? Give some examples in Java.
- Each data type in Java (and in many other languages) can be classified as
one of two kinds. What are they, and how are they different?
- What is a primitive type? What is a reference type
(or object type)?
- What is a method?
- Can a class have more than one method with the same name? If so, are there any
restrictions?
- What is a parameter? What is a return value?
- Can parameters and return values be primitive types? Reference types?
- What is type matching or type conformance?
- Define the following terms:
- instance variable or field
- global variable
- local variable
- formal parameter
- actual parameter
What is the scope and lifetime of each of these?
What is the difference between these? How are they related, if applicable?
- What is a constructor?
- What is meant by the state of an object?
- What is assignment? How is it different for reference types versus
primitive types? (This is a very important, but often misunderstood, concept!)
- What are accessor methods and mutator methods?
- What is a conditional statement? Give at least two examples.
- What is abstraction and why is it a good thing? Give some examples.
- What is modularization and why is it a good thing? Give some examples.
- In Java (and in C, C++, etc.), what are the following, and to
what data types can they be applied?
Do they have different meanings to different data types? If so, give examples.
- +, -, /, *
- <, >, ==, !=
- &&, ||, !
- %
- In Java (and in C++), what is the this keyword?
Why and when is it useful? Give examples. Is it ever necessary?
- Give two methods of performing a loop. Are there other ways of iterating
through a collection of items?
- What is casting? Why is it useful? Are there times when it is necessary?
- What is an anonymous object?
- What is an array? Is an array of fixed size? How do you access elements
in an array? Describe how to construct an arry. How is constructing an array of
primitives different than constructing an array of objects? (In fact, this is one
important place where Java and C++ differ.)
- What is an API? Why is it important?
- What is a library? How about a package? How do you use classes from a
package in Java?
- Besides arrays, what other ways are there of storing a collection of objects?
(This is the major topic of the second half of this course, but you should have
a partial answer to this question at this point.)
- Explain the difference between public and private methods and fields.
When is it appropriate to use each?
- What is meant by a class interface? How is this different than an application
interface?
- What does it mean for a class variable to be static? How about final?
How about both?
- What is a constant? When/why are they useful? How do you declare on in
Java? Are there any specific requirements for naming them? Are there
guidelines that should be followed in naming them? Why?
- What are testing and debugging? How are they related? How are they
different? Which is more important?
- Give at least 3 methods of testing and debugging.
- What is the difference between positive testing
and negative testing? Which is more important?
- What is regression testing and why is it important?
- What is a test rig or test harness?
- What is a walkthrough? Describe two ways you can perform a walkthrough.
- Is documentation important? Explain.
- What is coupling? Is it a good thing in OOP? Explain.
- What is cohesion? Is it a good thing in OOP? Explain.
- Is code duplication a good thing? Give an example that duplicates code, and show
how to fix it.
- What is encapsulation and how does it relate to OOP? What implications does
it have for the implementation of a class? Give specifics.
- What is refactoring? Is it a good thing or a bad thing? Explain.
- What does floccinaucinihilipilification mean?
- Inheritance and Abstraction
These questions may be a little more difficult to answer. They are related to the material from
Chapters 8-10 of the Objects First with Java (OFWJ) textbook. If you cannot answer all of
these by the end of the second week of class, you need to spend more time reviewing those chapters
of the textbook and/or getting help from me or the Computer Science Help Center.
- What is inheritance?
- What is an inheritance hierarchy?
- What is a subclass? A superclass?
- What are the advantages of using inheritance?
- What is the difference between an is-a and a has-a relationships?
- What is polymorphism? What is a polymorphic variable? Give an example.
What is a method polymorphism? Give an example.
- What is a wrapper class? Give several examples.
- What are overriding and overloading? Are they the same? Give examples.
- What is the equals method? Why is it useful? When should it be overridden?
How should it be overridden? What important detail needs to be pointed out about overriding equals?
- What does the keyword super mean? When is it used?
- What does the keyword protected mean? When is it used, and what does it do?
- What is meant by the static and dynamic types of a variable?
- What is an abstract class? When are they useful? Give an example.
- What is multiple inheritance? Why is it useful? Can it be done in Java?
Is there a substitute for it?
- What is an interface? Why are they useful?
- If a field or method has no access modifier (e.g. private), where can it be accessed? (This one is subtle.)
- Additional Questions
These questions are related to Chapters 12-13 from the Objects First with Java (OFWJ) textbook.
Although you likely didn't cover those sections in your previous course, you may have been exposed to
these concepts. I do not expect everyone to be able to answer these questions right away—we will
cover this material in the coming weeks. They are here so I can get a feel for what (if any) exposure
you have had to the concepts.
- What is an exception?
What is the difference between a checked exception and
an unchecked exception?
- What do the keywords throw and catch mean?
- How do you handle exceptions in Java?
- What is a design pattern? Why are they useful?
- Describe the following design patterns, giving an example.
- Decorator
- Singleton
- Client-Server
- Model-View-Controller (MVC)
- 3-tier