Posts

Showing posts from December, 2022

Exercise - Inheritance Polymorphism

Image
  Task 1: Implementing Inheritance and using Default Constructors   Given the following UML Class diagram:       a)    Create class definition for StaffUUM, Malaysian and International classes. b)    Create TestStaffUUMInheritance class to run the program. c)     In the TestStaffUUMInheritance class:                            I.           Create one object for each class. Use no-argument constructors (default constructors).                           II.           Call setter methods for each object to set their data.        ...

Exercise - Inheritance 1

1.      Here is a program that uses a class Video to represent videos available at a rental store. Try to trace out what will this program print.  class Video {   private String  title;    // name of the item   private int     length;   // number of minutes   private boolean avail;    // is the video in the store?     // constructor   public Video( String ttl )   {     title = ttl; length = 90; avail = true;   }     // constructor   public Video( String ttl, int lngth )   {     title = ttl; length = lngth; avail = true;   }     public void show()   {    System.out.println(title + ", " + length + " min. available:" + avail );   } }   public class VideoStore {   public static void main ( String args[] )   {     Video item1 = new Video("Jaws", 120 ...