Question

In: Computer Science

Java Problem: Abstraction is the basis for good Object-Oriented design that is modular, reusable, and maintainable....

Java Problem:

Abstraction is the basis for good Object-Oriented design that is modular, reusable, and maintainable.

Interfaces and Abstract classes are two mechanisms in Java that provide high-level abstractions. An interface or abstract class is something which is not concrete, something which is incomplete.

For this discussion, what do you think is meant by “Programming to an interface”? What are some differences between Abstract Classes and Interfaces? Provide a simple example application with an interface definition and a class which implements the interface.

Solutions

Expert Solution

SOURCE CODE:

*Please follow the comments to better understand the code.

**Please look at the Screenshot below and use this code to copy-paste.

***The code in the below screenshot is neatly indented for better understanding.



/* INTERFACE: In interface all the methods are declared but not defined.
* All the methods are public in an interface.*/

// create interface 1
public interface Interface1
{
    // just declare the methods don't define them
    void method1();
    void method2();
}

// create class by implementing new interface
class Class1 implements Interface1 {

    // define the methods here along with their body.
    @Override
    public void method1() {
        System.out.println("This is Method1");
    }

    @Override
    public void method2() {
        System.out.println("This is Method2");
    }
    // TEST the interface
     public static void main(String[] args) {
        // create object
        Class1 class1 = new Class1();
        // call methods
        class1.method1();
        class1.method2();
    }
}



======


Related Solutions

Abstraction is the basis for good Object-Oriented design that is modular, reusable, and maintainable. Interfaces and...
Abstraction is the basis for good Object-Oriented design that is modular, reusable, and maintainable. Interfaces and Abstract classes are two mechanisms in Java that provide high-level abstractions. An interface or abstract class is something which is not concrete, something which is incomplete. For this discussion, what do you think is meant by “Programming to an interface”? What are some differences between Abstract Classes and Interfaces? Provide a simple example application with an interface definition and a class which implements the...
modular design for object oriented data and process modeling...identify situations that are better aligned to one...
modular design for object oriented data and process modeling...identify situations that are better aligned to one method or the other and justify your recommendation.
Abstraction is a key part of object-oriented programming and the concepts apply particularly well to classes....
Abstraction is a key part of object-oriented programming and the concepts apply particularly well to classes. How would the same concepts apply to data structures and how we tend to define and think of ADTs?
Abstraction is a key part of object-oriented programming and the concepts apply particularly well to classes....
Abstraction is a key part of object-oriented programming and the concepts apply particularly well to classes. How would the same concepts apply to data structures and how we tend to define and think of ADTs?
Object-Oriented Design and Patterns in Java (the 3rd Edition Chapter 5) - Create a directory named...
Object-Oriented Design and Patterns in Java (the 3rd Edition Chapter 5) - Create a directory named as the question number and save the required solutions in the directory. - Each problem comes with an expected tester name. In the directory for a given problem, including the tester and all java classes successfully run this tester. Exercise 5.2 ObserverTester.java - Improve Exercise 1 by making the graph view editable. Attach a mouse listener to the panel that paints the graph. When...
i need a full explanation in details Object Oriented Programming Principles Principles Polymorphism Inheritence Encapsulation Abstraction...
i need a full explanation in details Object Oriented Programming Principles Principles Polymorphism Inheritence Encapsulation Abstraction Class Object Method Message Passing
Problem Write a movie management system using object-oriented design principles. The program will read from the...
Problem Write a movie management system using object-oriented design principles. The program will read from the supplied data file into a single array list. The data file (movies.txt) contains information about the movies. Each movie record has the following attributes: - Duration (in minutes) - Title - Year of release Each record in the movies.txt file is formatted as follows: - Duration,Title,Year - e.g.: 91,Gravity,2013 Specifically, you have to create an interactive menu driven application that gives the user the...
Explain Basic Characteristics of Object Oriented System Analysis & Design.
Explain Basic Characteristics of Object Oriented System Analysis & Design.
What are design patterns in object oriented programming? Minimum 200 words
What are design patterns in object oriented programming? Minimum 200 words
What factors should be considered in selecting a design strategy? (object oriented design and analysis) Name...
What factors should be considered in selecting a design strategy? (object oriented design and analysis) Name different computing Client-Server architectures and give examples of the architectures. What are the main principles for User Interface Design? Describe any one of the principles in detail. Name five steps in the user interface design process. Describe types of navigation control in the user interface. Name basic principles of output design.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT