Question

We have written the following Class1 class: class Class1 implements SecretInterface { // instance variable private...

We have written the following Class1 class:

class Class1 implements SecretInterface {
    // instance variable
    private int x = 0;

    // constructor
    public Class1(int x) {
        this.x = x;
    }

    // instance methods
    public double myMethod1(double x, double y) {
        return x - y;
    }
    public void myMethod2(int x) {
        System.out.println(x);
    }
    public String myMethod3(String x) {
        return "hi " + x;
    }
}

We have also written the following Class2 class:

class Class2 implements SecretInterface {
    // instance variable
    private int x = 1;

    // constructor
    public Class2(int x) {
        this.x = x;
    }

    // instance methods
    public double myMethod1(double a, double b) {
        return a + b;
    }
    public void myMethod2(double x) {
        System.out.println(x);
    }
    public String myMethod3(Object o) {
        return "hello";
    }
}

TASK: Write the SecretInterface interface such that it contains the most possible attributes/methods possible given the implementations of Class1 and Class2 above.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer :

interface SecretInterface{
   double myMethod1(double x,double y);
}

only the myMethod1 is common between the Class1 and Class 2

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
We have written the following Class1 class: class Class1 implements SecretInterface { // instance variable private...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • We have written the following Node class: class Node { // instance variables private int value;...

    We have written the following Node class: class Node { // instance variables private int value; private Node next; // constructor public Node(int value) { this.value = value; } // get the 'next' variable public Node getNext() { return this.next; } // get the 'value' variable public int getValue() { return this.value; } // set the 'next' variable public void setNext(Node next) { this.next = next; } } TASK: Create a class called List that has the following properties: It...

  • 4. Command pattern //class Stock public class Stock { private String name; private double price; public...

    4. Command pattern //class Stock public class Stock { private String name; private double price; public Product(String name, double price) { this.name = name; this.price = price; } public void buy(int quantity){ System.out.println(“BOUGHT: “ + quantity + “x “ + this); } public void sell(int quantity){ System.out.println(“SOLD: “ + quantity + “x “ + this); } public String toString() { return “Product [name=” + name + “, price=” + price + “]”; } } a. Create two command classes that...

  • You are to create a class Appointment.java that will have the following: 5 Instance variables: private...

    You are to create a class Appointment.java that will have the following: 5 Instance variables: private String month private int day private int year private int hour private int minute 1 default constructor public Appointment() 1 non-default constructor that accepts arguments for all instance variables, your constructor must call the setter methods below to set the values of the instance variables public Appointment(String monthPassed, int dayPassed, int yearPassed, int hourPassed, int minutePassed) 5 setter methods (one for each instance variable)...

  • q2: Write a public class named MythMouseListener that implements the Mouselistener interface. This class will have...

    q2: Write a public class named MythMouseListener that implements the Mouselistener interface. This class will have a public constructor that takes a JTextArea and a JLabel as parameters and stores these in instance variables. Override the mouseEntered method to . display the text from the JTextArea on the JLabel in all upper case letters. Then, override the mouseReleased method to display the text from the JTextArea on the JLabel in all lower case letters. The other three methods from the...

  • public class Car {    /* four private instance variables*/        private String make;   ...

    public class Car {    /* four private instance variables*/        private String make;        private String model;        private int mileage ;        private int year;        //        /* four argument constructor for the instance variables.*/        public Car(String make) {            super();        }        public Car(String make, String model, int year, int mileage) {        super();        this.make = make;        this.model...

  • public class Item implements Comparable { private String name; private double price; /** * Constructor for...

    public class Item implements Comparable { private String name; private double price; /** * Constructor for objects of class Item * @param theName name of item * @param thePrice price of item */ public Item(String theName, double thePrice) { name = theName; price = thePrice; }    /** * gets the name * @return name name of item */ public String getName() { return name; }    /** * gets price of item * @return price price of item */...

  • GIVEN CODES *****Boat.java***** import java.util.HashSet; import java.util.Set; public class Boat { private String name; //private instance...

    GIVEN CODES *****Boat.java***** import java.util.HashSet; import java.util.Set; public class Boat { private String name; //private instance variable name of type String private String boatClass; //private instance variable boatClass of type String private int regNum; //private instance variable regNum of type int private Set<String> crew = new HashSet<String>(); public void setName(String name) { this.name = name; } public void setBoastClass(String boatClass) { this.boatClass = boatClass; } public void setRegNum(int regNum) { this.regNum = regNum; } public String getName() { return name;...

  • ble and instance variable, and then use clas 4. Please discuss the difference between class variable...

    ble and instance variable, and then use clas 4. Please discuss the difference between class variable and instant variable to complete the following code for the count of number of stud public class Student _//q1: fill this line to create a class variable num. public Student 1/ 22: fill this line to increase num. public static int getNum() return num; public static void main(String[] args) { Student stl=new Student O; Student st2-new Student ; Student st3-new Student ; //q3: fill...

  • Update your Assignment 4 as follows (Assignment 4 codes will be on the bottom) Create a...

    Update your Assignment 4 as follows (Assignment 4 codes will be on the bottom) Create a new method called displayAll, that takes an ArrayList (of your base class) as a parameter, and doesn't return anything [25 pts] The displayAll method will loop through the ArrayList, and call the display (or toString) method on each object   [25 pts] In the main method, create an ArrayList containing objects of both your base class and subclass. (You should have at least 4 objects)  [25...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT