Java Reference
In-Depth Information
Review Questions
1. What is the result of the following code?
1. public class Shape {
2. private String color;
3.
4. public Shape(String color) {
5. System.out.print(“Shape”);
6. this.color = color;
7. }
8.
9. public static void main(String [] args) {
10. new Rectangle();
11. }
12. }
13.
14. class Rectangle extends Shape {
15. public Rectangle() {
16. System.out.print(“Rectangle”);
17. }
18. }
A. ShapeRectangle
B. RectangleShape
C. Rectangle
D. Line 4 generates a compiler error.
E. Line 15 generates a compiler error.
2. Given the following class definitions:
1. public class Parent {
2. public Parent() {
3. System.out.print(“A”);
4. }
5. }
6.
7. class Child extends Parent {
8. public Child(int x) {
9. System.out.print(“B”);
10. }
11.
Search WWH ::




Custom Search