daniel_lawson9999

Daniel Lawson Chapter 9 Self Check evens

Oct 26th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.01 KB | None | 0 0
  1. Daniel Lawson
  2. 9.1 evens
  3.  
  4. 2. Overloading is when you have two methods with the same name in a class but wih different parameters.
  5. Overiding is creating a method that already has the same name in the parent class.
  6.  
  7. 4.
  8. a, b, c, d are legal
  9.  
  10. 9.2
  11.  
  12. 6.
  13.  
  14. It can call the set age method but the age and name fields are private so it cannot directly refer to it.
  15.  
  16. 8.
  17.  
  18. public void setAge(int age){
  19.    super.setAge(age);
  20.    year++;
  21.  
  22. }
  23.  
  24. 10.
  25. outputs:
  26.  
  27. vroomvroom
  28. truck 1
  29. car 1
  30.  
  31. 9.3
  32.  
  33. 12.
  34.  flute
  35.  shoe 1
  36.  flute 2
  37.  
  38.  flute
  39.  blue 1
  40.  flute 2
  41.  
  42.  moo
  43.  moo 1
  44.  moo 2
  45.  
  46.  moo
  47.  blue 1
  48.  boo m2
  49.  
  50. 14.
  51. squid
  52. creature 1
  53. tentacles
  54.  
  55. BIG!
  56. spout
  57. create 2
  58.  
  59. ocean-dwelling
  60. create 1
  61. create 2
  62.  
  63. ocean-dwelling
  64. warm-blooded
  65. creature 2
  66.  
  67. 16.
  68. Bay 1 Pond 2
  69. Ocean 2
  70. Lake 3 Ocean 2
  71.  
  72. Pond 1
  73. Pond 2
  74. Pond 3
  75.  
  76. Pond 1
  77. Pond 2
  78. Pond 3 Pond 2
  79.  
  80. Bay 1 Pond 2
  81. Bay 2
  82. Lake 3 Bay 2
  83.  
  84. 18.
  85. In a "is-a" relationship one class extends another, in a "has-a" relationship one class uses another class as a field.
  86. You declare the object like you would a normal field.
  87.  
  88. 20.
  89. It is a bad design because you have to create so many different classes. Instead you could make one class for a generic card
  90. and then possibly have another class called deck with stores large amounts of cards.
  91.  
  92. 9.5
  93.  
  94. 22.
  95.  
  96. Implementing an interface allows for a class to be manipulated in the client class similar to if it was extending a client,
  97. except it does not inherent methods and fields.
  98.  
  99. 24.
  100. interfaecs can't have fields or have actual methods
  101. correct interface:
  102.  
  103. public interface Colored{
  104.        public Color getColor();
  105. }
  106.  
  107. 26.
  108. // in shape
  109. public int getSideCount();
  110.  
  111. //in triangle
  112. public int getSideCount(){
  113.    return 3;
  114. }
  115. // in rectangle
  116. public int getSideCount(){
  117.    return 4;
  118. }
  119. //in circle
  120. public int getSideCount(){
  121.    return 0;
  122. }
  123.  
  124. 9.6
  125.  
  126. 28.
  127. The OrdereredByLength class has the GetElement method which it inherented and it also must have a arrange method because it was abstracted in the inherited class
Advertisement
Add Comment
Please, Sign In to add comment