Question

In: Computer Science

The abstract class SayHello and the static method process are defined as followed: class SayHello {...

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 );

}

Solutions

Expert Solution

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 ********************************************************


Related Solutions

Create an abstract class DiscountPolicy. It should have a single abstract method computeDiscount that will return...
Create an abstract class DiscountPolicy. It should have a single abstract method computeDiscount that will return the discount for the purchase of a given number of a single item. The method has two parameters, count and itemCost. Derive a class BulkDiscount from DiscountPolicy. It should have a constructor that has two parameters minimum and percent. It should define the method computeDiscount so that if the quantity purchased of an item is more then minimum, the discount is percent percent.
- Class DiscountPolicy is an abstract class with a method called computeDiscount, which returns the discount...
- Class DiscountPolicy is an abstract class with a method called computeDiscount, which returns the discount for the purchase of items. DiscountPolicy knows the name of the item and its cost as well as the number of items being purchased. - Class BulkDiscount, derived from DiscountPolicy, has two fields, minimum and percentage. computeDiscount method will return the discount based on the percentage applied, if the quantity of items purchased is more than minimum. For example: if minimum is 3 and...
USING JAVA: complete these one method in the BasicBioinformatics class /** * Class BasicBioinformatics contains static...
USING JAVA: complete these one method in the BasicBioinformatics class /** * Class BasicBioinformatics contains static methods for performing common DNA-based operations in * bioinformatics. * * */ public class BasicBioinformatics { /** * Calculates and returns the reverse complement of a DNA sequence. In DNA sequences, 'A' and 'T' * are complements of each other, as are 'C' and 'G'. The reverse complement is formed by * reversing the symbols of a sequence, then taking the complement of each...
USING JAVA: complete the method below in the BasicBioinformatics class. /** * Class BasicBioinformatics contains static...
USING JAVA: complete the method below in the BasicBioinformatics class. /** * Class BasicBioinformatics contains static methods for performing common DNA-based operations in * bioinformatics. * * */ public class BasicBioinformatics { /** * Calculates and returns the number of times each type of nucleotide occurs in a DNA sequence. * * @param dna a char array representing a DNA sequence of arbitrary length, containing only the * characters A, C, G and T * * @return an int array...
Name the project pa3 [Method 1] In the Main class, write a static void method to...
Name the project pa3 [Method 1] In the Main class, write a static void method to print the following text by making use of a loop. Solutions without a loop will receive no credit. 1: All work and no play makes Jack a dull boy. 2: All work and no play makes Jack a dull boy. 3: All work and no play makes Jack a dull boy. 4: All work and no play makes Jack a dull boy. [Method 2]...
Error: Main method is not static in class ArrayReview, please define the main method as: public...
Error: Main method is not static in class ArrayReview, please define the main method as: public static void main(String[] args) please help me fast: import java.util. Random; import java.util.Scanner; //ArrayReview class class ArrayReview { int array[];    //constructor ArrayReview (int n) { array = new int[n]; //populating array Random r = new Random(); for (int i=0;i<n; i++) array[i] = r.nextInt (); } //getter method return integer at given index int getElement (int i) { return array[i]; }    //method to...
3. [Method 1] In the Main class, write a static void method to print the following...
3. [Method 1] In the Main class, write a static void method to print the following text by making use of a loop. Solutions without a loop will receive no credit. 1: All work and no play makes Jack a dull boy. 2: All work and no play makes Jack a dull boy. 3: All work and no play makes Jack a dull boy. 4: All work and no play makes Jack a dull boy. 4. [Method 2] In the...
Design an application with a single class and two static methods: method main and method isLeap....
Design an application with a single class and two static methods: method main and method isLeap. Static method isLeap accepts year as integer and returns boolean value true or false depending whether year is leap or not. public static boolean isLeap ( int year ) The year is leap year if it is divisible by 4, but not divisible by 100 except if it is divisible by 400. Examples 2007 is not a leap year 2008 is leap year 1700...
Create an abstract class polygon that has a method getnoofsides() and getarea() and it has three...
Create an abstract class polygon that has a method getnoofsides() and getarea() and it has three subclasses triangle, rectangle and square each with its own two methods getnoofsides and getarea and their respective implementations accordingly. python
Design a Geometry class with the following methods: * A static method that accepts the radius...
Design a Geometry class with the following methods: * A static method that accepts the radius of a circle and returns the area of the circle. Use the following formula: Area=?r^2 * A static method that accepts the length and width of a rectangle and returns the area of the rectangle. Use the folliwng formula: Area = Length x Width * A static method that accepts the length of a triangle's base and the triangle's hight. The method should return...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT