Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4272974
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:39:01+00:00 2026-05-21T07:39:01+00:00

Below I have a Person interface, an implementing class and a driver class which

  • 0

Below I have a Person interface, an implementing class and a driver class which initialises the Person with a name and just outputs it again. What is the advantage of using

Person person = new PersonImpl();

instead of

PersonImpl person = new PersonImpl();

The interface is supposed to be hiding the implementation?
Is this the correct way of using interfaces?

public class Driver {

    public static void main(String [] args)
    {
        Person person = new PersonImpl();
        person.setName("test name");
        System.out.println("Name is "+person.getName());
    }

}


public interface Person {

    public void setName(String name);

    public String getName();

}


public class PersonImpl implements Person{

    private String name;

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:39:02+00:00Added an answer on May 21, 2026 at 7:39 am

    This is the way to use interfaces.

    The reason is so you could write another implementation later without changing code that uses Person.

    So for now you can use PersonImpl but later you might need a OtherTypeOfPersonImpl.

    You could create the new class implementing the same interface, and you could use the new class with any other code that expects a Person.

    A good example is the List interface.

    There are multiple implementations of List such as ArrayList, LinkedList, etc. Each of these has advantages and disadvantages. By writing code that uses List, you can let each developer decide what type of List works best for them and be able to handle any of them without any changes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the below query, which basically it retrieves the 5 top most books
I have the below code in stdafx.h. using namespace std; typedef struct { DWORD
Below are the object types I have. Basically I have a person table and
As mentioned below I have made changes to the code which looks like following
I have 2 tables: Person and Item. I just created a new column in
Below I have a very simple example of what I'm trying to do. I
I have below a list of text, it is from a popular online game
In the example below I have a ListBox with dozens of font names in
Solution to original problem (below) may have been discovered. I commented out <identity> ...
Edit: I have solved this by myself. See my answer below I have set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.