Can you help please. I do not know how to change the code so that this error does not occur. You do not need to use mutable objects.
public class Lab8 { class Device { String name; String model; String year; public String getName(){ return name; } public String getModel(){ return model; } public String getYear(){ return year; } public Device(String name, String model, String year){ this.name=name; this.model=model; this.year=year; } public void display(){ System.out.println("Name: " + name); System.out.println("Model: " + model); System.out.println("Year: " + year); } } class Laptop extends Device{ public Laptop(String name, String model, String year) { super(name, model, year); } } class Tablet extends Device{ public Tablet(String name, String model, String year) { super(name, model, year); } @Override public void display(){ System.out.printf("Name -> :) %s \n", getName()); System.out.printf("Model -> :) %s \n", getModel()); System.out.printf("Year -> :) %s \n", getYear()); } } class PC extends Device { public PC(String name, String model, String year) { super(name, model, year); } } public static void main(String[] args){ Laptop Laptop = new Laptop("Laptop", "ASUS", "2018"); Laptop.display(); Tablet Tablet = new Tablet("Tablet", "SONY", "2010"); Tablet.display(); PC PC = new PC("PC", "HP", "2017"); PC.display(); } }
static class Deviceor bring it out from under theclass Lab8. Google by keywordinner class- pavel