syu nizam
inherintance
0 Answer(s)      2 years and 10 months ago
Posted in : Java Beginners

class Video { String title; // name of the item int length; // number of minutes 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 ); Video item2 = new Video("Star Wars" ); item1.show(); item2.show(); } }

Let?s make a Movie class that is similar to Video, but also includes the name of the director and a rating. The class is given as follows:

class Movie extends Video { String director; // name of the director String rating; // U, SG, SX // constructor public Movie( String ttl, int lngth, String dir, String rtng ) { super( ttl, lngth ); //use the super class's constructor director = dir; rating = rtng; } }

The class Movie is a subclass of Video. List all of the members of a Movie object and for each member state whether it is inherited from Video or defined in Movie.

Advertisement
View Answers









Related Tutorials/Questions & Answers: