Question

Using the interface and class definitions below, write the headings of all of the methods which...

Using the interface and class definitions below, write the headings of all of the methods which still need to be defined in the class Class2.

https://hastebin.com/kopejolila.java

 public interface Interface1 { 
     public float method1(int i) ;
  }

  public interface Interface2 extends Interface1 {
     public int method2(int i) ; 
     public void method3(int i) ; 
  } 

  public abstract class Class1 {
     public float method1(int anInt) {
        return anInt * 2.0f ;
     } 
     public abstract void method3(Object anObject) ; 
     public abstract void method4(int anInt) ; 
  }

  public class Class2 extends Class1 implements Interface2 {  
     public void method3(int anInt) {
        System.out.println(anInt) ;
     }
       What other method headings need to be defined here?
  }

List the headings of methods that still must be defined in Class2 in the box below so that Class2 will compile.

Homework Answers

Answer #1

Answer.)

To Compile Class 2, the below methods needs to be overridden :

  • public int method2(int i)
  • public void method3(Object anObject)
  • public void method4(int anInt)

Explanation: As Class 2 extends Class 1, which already has the implementation of method1(), it is not required to override. However, method3(Object anObject) of Class 1 needs to be overridden as the method arguments are different as implemented in Class 2. Also, as Class 2 implements Interface 2 and extends Class 1, so abstract methods - method2(int I) of Interface 2 and method4(int anInt) of Class 1 needs to be implemented.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Question 6 (6 pts) The interface SayHello is defined as followed: public interface SayHello {             void...
Question 6 (6 pts) The interface SayHello is defined as followed: public interface SayHello {             void printGreeting( ); } Write the statements to instantiate an object of the anonymous class that implements the above interface by using the following definition of printGreeting(   ) and then call the instance method printGreeting( ). void  printGreeting(    ) {             System.out.println(“Hello guys”); } Question 7 (8 pts) The abstract class SayHello and the static method process are defined as followed: class SayHello {             private String greeting; SayHello(  ...
3.2 Class Dictionary This class implements a dictionary using a hash table in which collisions are...
3.2 Class Dictionary This class implements a dictionary using a hash table in which collisions are resolved using separate chaining. The hash table will store objects of the class Data. You will decide on the size of the table, keeping in mind that the size of the table must be a prime number. A table of size between 5000-10000, should work well. You must design your hash function so that it produces few collisions. A bad hash function that induces...
Casting class objects 1.2 Compile and execute the code listed below as it is written. Run...
Casting class objects 1.2 Compile and execute the code listed below as it is written. Run it a second time after uncommenting the line obj.speak();. public class AnimalRunner {    public static void main(String[] args)    {       Dog d1 = new Dog("Fred");       d1.speak();       Object obj = new Dog("Connie");       // obj.speak();    } } The uncommented line causes a compile error because obj is an Object reference variable and class Object doesn’t contain a speak() method. This...
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields,...
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields, as well as the methods for the Inventory class (object). Be sure your Inventory class defines the private data fields, at least one constructor, accessor and mutator methods, method overloading (to handle the data coming into the Inventory class as either a String and/or int/float), as well as all of the methods (methods to calculate) to manipulate the Inventory class (object). The data fields...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class Food {     static int count;     private String flavor = "sweet";     Food() { count++; }     void setFlavor(String s) { flavor = s; }     String getFlavor() { return flavor; }     static public void main(String[] args) {         Food pepper = new Food();         System.out.println(pepper.getFlavor());     } } a. a class variable b. a constructor c. a local object variable d....
What is the output of the following Java program? public class Food {     static int...
What is the output of the following Java program? public class Food {     static int count;     private String flavor = "sweet";     Food() { count++; }     void setFlavor(String s) { s = flavor; }     String getFlavor() { return flavor; }     static public void main(String[] args) {         Food pepper = new Food();         pepper.setFlavor("spicy");         System.out.println(pepper.getFlavor());     } } Select one: a. sweet b. 1 c. The program does not compile. d. 2 e. spicy...
For this part, you will write a PostfixCalculator class that has methods for processing each possible...
For this part, you will write a PostfixCalculator class that has methods for processing each possible input. You will write a Tester class that reads a line of input from the user, with each symbol separated by a space, and prints out the numeric value of the top of the stack. If the user specifies an incomplete expression, print out the top of the stack and print out a message saying that the stack contains more than one item. If...
Mention the concepts analyzed from the below given program and write the output. [0.5 M] class...
Mention the concepts analyzed from the below given program and write the output. [0.5 M] class Test { int a, b; Test(int i, int j) { a = i; b = j; } void meth(Test s) { s.a *= 2; s.b /= 2; } } class demo { public static void main(String args[]) { Test ob = new Test(15, 20); System.out.println("Before call: " + ob.a + " " + ob.b); ob.meth(ob); System.out.println("After call: " + ob.a + " " +...
1. Consider the following interface: interface Duty { public String getDuty(); } a. Write a class...
1. Consider the following interface: interface Duty { public String getDuty(); } a. Write a class called Student which implements Duty. Class Student adds 1 data field, id, and 2 methods, getId and setId, along with a 1-argument constructor. The duty of a Student is to study 40 hours a week. b. Write a class called Professor which implements Duty. Class Professor adds 1 data field, name, and 2 methods, getName and setName, along with a 1-argument constructor. The duty...
<<<<<<<< I need only the UML diagram for ALL classes.Java???????????? public class House {    private...
<<<<<<<< I need only the UML diagram for ALL classes.Java???????????? public class House {    private int houseNumber;    private int bedrooms;    private int sqFeet;    private int year;    private int cost;    public House(int houseNumber,int bedrooms,int sqFeet, int year, int cost)    {        this.houseNumber = houseNumber;        this.bedrooms = bedrooms;        this.sqFeet = sqFeet;        this.year = year;        this.cost = cost;    }    public int getHouseNumber()    {        return houseNumber;    }   ...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT