Decide an appropriate datatype for each attribute and

This preview shows page 3 - 6 out of 7 pages.

Decide an appropriate datatype for each attribute and return type for each method. You will alsoneed to decide the parameter types for all mutator methods.Decide an appropriate public/private modifier for each variable and each method.*
CSE 205Spring 2017Page 49. Study the class diagram and the code that follows. Then fill in the three blanks given below. [6points]Vehicle[] vehicleList = new Vehicle[3];vehicleList[0] = new Vehicle();vehicleList[1] = new Truck();vehicleList[2] = new Car();for (int i=0; i <= 2; i++)vehicleList[i].move();a) vehicleList[0].move() refers to move() of____Vehicle___classb) vehicleList[1].move() refers to move() of_____Truck___classc) vehicleList[2].move() refers to move() of____Vehicle____classSection 3:Output Problems [Total 22 points]10. Study the code segment given below and write the output of this code in the space providedbelow. [10 points]public class Split1{public static void main(String[] args){String line = "/computer//science/";String[] words = line.split("/");System.out.println("\nsize " + words.length);for (int i=0; i<words.length; i++)System.out.println(words[i] + " with length" + words[i].length());}}size 4with length0computer with length8with length0science with length7VehicleCarmove()move()Truck
CSE 205Spring 2017Page 511. Write the output when the following code is executed. Consider the polymorphic invocation.[12 points]public class A{void doSomething(){System.out.println("Class A");}}public class B extends A{void doSomethingB(){System.out.println("Class B");}}public class C extends A{void doSomething(){System.out.println("Class C");}}public class D extends B{void doSomething(){System.out.println("Class D");}}public class TestInheritance{public static void main(String [] main){A obj1 = new A();B obj2 = new B();C obj3 = new C();D obj4 = new D();obj1.doSomething();obj1 = obj2;obj1.doSomething();obj1 = obj3;obj1.doSomething();obj4.doSomethingB();}}Class AClass AClass CClass B

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 7 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Spring
Professor
Matasu
Tags
Object Oriented Programming, class a, public class

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture