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

  • Home
  • SEARCH
  • 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 7062611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:36:53+00:00 2026-05-28T04:36:53+00:00

In a current problem I am having ( printing a file to a physical

  • 0

In a current problem I am having (printing a file to a physical printer in Java) I have been running through the code like a madman trying to devour any useful missed information from the javadoc of each class used.

Now, I pulled quite a bit of this code from previous questions so there was a fair bit I didn’t write myself. The issue I noticed is that the code I grabbed is initializing an object, say “SimpleDoc” which implements an interface (Doc) and assigning it to that interface?!

Little Code snippet:

Doc mydoc = new SimpleDoc(textStream, flavor, null);

Now as far as I was led to understand in java we create objects. I’m familiar with inheritance, and I’m familiar with the trick of using interfaces to allow a class to “inherit” multiple super classes.

But this just isn’t sticking right. You can create a class which implements an interface, that is fine with me. But what is happening here when a interface is created and an object is reduced to its interface? What am I accessing when I reference mydoc exactly?

  • 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-28T04:36:54+00:00Added an answer on May 28, 2026 at 4:36 am

    The trick is to realize that you’re not “creating”, “instantiating”, or “initializing” an interface. You are simply defining a variable as being something that you know implements that interface.

    You are essentially telling other programmers working on this code that for the rest of this method, you are only interested in the fact that myDoc is a Doc (i.e., something that satisfies the Doc interface). This can make programming simpler because the IDE’s auto-complete will now only show you the methods that are defined by this interface, rather than everything that a SimpleDoc is capable of doing.

    Imagine that in the future you want to expand your functionality so that you could have different implementations of Doc depending on some input. Rather than creating the SimpleDoc explicitly, you say:

    Doc mydoc = docFactory.getByType(inputType);
    

    The docFactory can produce any type of Doc, and this method doesn’t really care what kind gets instantiated, because it’s going to treat it like a Doc regardless.

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

Sidebar

Related Questions

The following code summarizes the problem I have at the moment. My current execution
My current problem is that I have a JFrame with a 2x2 GridLayout. And
Problem, there's no method: bool ChangePassword(string newPassword); You have to know the current password
Having problem with this bit of code qith jQuery. it should pick the values
I am having problem closing current form when I call some other form from
i'm having a problem with parsing the json data from hello.json to the current
I'm having a problem with configuring CC.Net. My current setup for the project looks
Current I having problem on using CSS position:fixed in my IE 7, Noticed it
I am having problem with rspec testing controller the devise authentication. I have a
I want to fix the Background while only the ListFields scrolls. Current Problem: Scrolling

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.