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. ...
1. Write TWO (2) different ways to create an object from the String class. - define literally (String str = “Hello!”; ) - using new operator 2. What is the output for the following Java statements? String phr = new String("Big,blue sky"); System.out.println(phr.substring(phr.indjexOf(","),7)); Ans: ,blu 3. Give your description on the output that will be produced by the execution of the following statements. Random rd = new Random(); System.out.println(rd.nextInt(41) + 10); Ans: The output will be a random number from 0 to 40 which is added with 10. 4. Write Java code segment that use class Random to generate two random numbers that is great...
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 ...
Comments
Post a Comment