In: Computer Science
The abstract class SayHello and the static method process are defined as followed:
class SayHello
{
private String greeting;
SayHello( )
{
greeting = “Hello guys”;
}
SayHello( String wts )
{
greeting = wts;
}
void printGreeting( );
}
static void process( SayHello obj )
{
obj.printGreeting( );
}
Write the statements to instantiate an object (with its instance variable initialized with the string “Bonjour mes amis” ) of the anonymous class that extends this abstract class by using the following definition of printGreeting( ); then write a statement to call method process by passing to it that object.
void printGreeting( )
{
System.out.println( greeting );
}
SayHello.java
public abstract class SayHello {
protected String greeting;
public SayHello()
{
greeting = "Hello guys";
}
public SayHello(String wts) {
greeting = wts;
}
public abstract void printGreeting();
}
SayHelloSuper.java
public class SayHelloSuper extends SayHello {
public SayHelloSuper()
{
super();
}
public SayHelloSuper(String wts) {
super(wts);
}
@Override
public void printGreeting() {
System.out.println(greeting);
}
}
ProcessMain.java (Driver/Main class)
public class ProcessMain {
public static void main(String[] args) {
SayHelloSuper sayHelloSuper1 = new SayHelloSuper();
SayHelloSuper sayHelloSuper2 = new SayHelloSuper("Bonjour mes
amis");
System.out.println("Initializing an instance of SayHelloSuper class
with default constructor..\nResult of calling the method
printGreeting()..");
process(sayHelloSuper1);
System.out.println("\nInitializing another instance of
SayHelloSuper class with parameterized constructor..\nResult of
calling the method printGreeting()..");
process(sayHelloSuper2);
}
public static void process(SayHello obj)
{
obj.printGreeting();
}
}
******************************************************** SCREENSHOT ********************************************************