Answer these questions:
Chapter 2 Test Review
The Java Language
1. What is encapsulation and what is the purpose?
2. Explain abstractions. Give an example of an abstraction.
3. Give the code to concatenate two strings “hello” and “goodbye”.
4. List the escape sequences and the meaning.
5. Write the statement to print “Hello World” including the quotes.
5. List all primitive data types you know.
6. What is the difference between a character and a string.
7. Do you need to cast when assigning a double to an integer? why or why not?
8. Do you need to cast when assigning an integer to a double? why or why not?
9. Give an example of widening and narrowing type conversion for each.
10. What is the purpose of casting when using a casting operator in the case of narrowing type conversion.
11. What does “123456789”.substring(3,6) return?
12. Write a main method that prompts the use for two numbers, x and y, and it displays it back the following format: (x,y).
13. Write a code snipped to compare two strings, s1 and s2. If s1 comes first in the lexicographic order, then it will print “move two steps forward” else “move two steps backwards.
14. What is the result of 21 % 6 when evaluated in a java expression?
Object Oriented Design
1. What are classes like?
2. What is the content of an object variable?
3. Why the “= =” cannot be used to compare objects?
4. What is an instance of a class?
5. In the following code: BankAccount myAcct = new BankAccount(); Is myAcct an object of BankAccount?
6. What is the purpose of a constructor?
7. Can you have multiple constructors?
8. What is the return type of a constructor?
9. What does the operator new do?
10. What does it mean a string object is inmutable?
11. What is a wrapper class? What is autoboxing? Give clear examples.
Homework:
Do the self-review questions at the end of the chapter.
Reflect on this article: