Here is an example of what I'm trying to ask
superclass Name.java
public class Name{ protected String first; protected String last; public Name(String firstName, String lastName){ this.first = firstName; this.last = lastName; } public String initials(){ String theInitials = first.substring(0, 1) + ". " + last.substring(0, 1) + "."; return theInitials; }
and then subclass - ThreeNames.java
public class ThreeNames extends Name{ private String middle; public ThreeNames(String aFirst, String aMiddle, String aLast){ super(aFirst, aLast); this.middle = aMiddle; } public String initials(){ String theInitials = super.first.substring(0, 1) + ". " + middle.substring(0, 1) + ". " + super.last.substring(0, 1) + "."; return theInitials; }
so if I create a Threename object using ThreeNames example1 = new ThreeNames("Bobby", "Sue" "Smith") , then call System.out.println(example1.initials()); I will get BSS , I will get it.
My question is how to call the initials method, which is in the Name class, so my output is BS
Kailua bum
source share