Final answer:
The sample Java program showcases a class hierarchy with a base class 'Comp', and derived classes 'Laptop' and 'Book', each with constructors and display methods. The main class creates instances and prints their details.
Step-by-step explanation:
To address your question on how to write a Java program for the given classes, here's a simple example:
//Base class for all devices
class Comp {
String type;
String brand;
double cpuSpeed;
int ramSize;
// Constructor for Comp
Comp(String type, String brand, double cpuSpeed, int ramSize) {
this.type = type;
this.brand = brand;
this.cpuSpeed = cpuSpeed;
this.ramSize = ramSize;
}
The program above defines a base class Comp with attributes type, brand, cpu speed, and ram size, as well as a method to display the computer details. It then defines two subclasses, Laptop and Book, each with additional attributes and overridden display methods to account for these. The main class creates objects and calls their display methods to show details of the computer, laptop, and book.