1. Engineering
  2. Computer Science
  3. this assignment will consist of three java files the first...

Question: this assignment will consist of three java files the first...

Question details

This assignment will consist of three Java files.

The first file will be a class definition for a Thing class. Your Thing class definition will contain three members. The first member will be an int class level variable. This variable will be named count and will be declared static. The value of count will be set to zero. The second member will be a constructor. This constructor will increment count each time a Thing object is instantiated. The third member will be an accessor method named getCount that will return the value of count when it is called.

Your second file will be a class definition for a Widget class. The Widget class will be a subclass of the Thing class. The Widget class will contain three members. The first member will be a class level String variable named name. The second member will be a constructor. This constructor will do two things. It will call the Thing constructor and it will assign a value to the name variable. There are two ways to accomplish this second task. The method you chose is up to you. A word of advice, calling a method from a constructor is almost always poor programming. The third member will be an accessor method named getName that will return the value of name when it is called.

Your third file will be a Java application (Test.java). This application will instantiate an object of the Thing class and print to the command prompt window the value of count. Next it will instantiate an object of the Widget class and print to the command prompt window the name of the Widget object and the value of count.

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution