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 7783325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:48:17+00:00 2026-06-01T19:48:17+00:00

In java, an interface contains only the method type, name and parameters. The actual

  • 0

In java, an interface contains only the method type, name and parameters. The actual implementation is done in a class that implements it. Given this, how is it possible to create an instance of a interface and use it as if it were a class object? There are many such interfaces, such as org.w3c.dom.Node.

This is the code that I am using:

DocumentBuilderFactory fty = DocumentBuilderFactory.newInstance();
fty.setNamespaceAware(true);
DocumentBuilder builder = fty.newDocumentBuilder();
ByteArrayInputStream bais = new ByteArrayInputStream(result.getBytes());
Document xmldoc = builder.parse(bais);
NodeList rm1 = xmldoc.getElementsByTagName("Subject");
Node rm3 = rm1.item(0);
  • 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-06-01T19:48:19+00:00Added an answer on June 1, 2026 at 7:48 pm

    You never create an instance of just the interface. You can have a field/parameter/local variable of that interface type, but that’s fine – the value that is assigned to such a variable will always be either null or a reference to an instance of some concrete implementation of the interface. The point is that code which deals only with the interface shouldn’t need to care what the implementation is.

    A good example is Collections.shuffle(List) – I can provide that any list implementation, and it will only use the methods declared in the interface. The actual object will always be an instance of some concrete implementation, but the shuffle method doesn’t need to know or care.

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

Sidebar

Related Questions

I have a Java interface in an API that contains a single method: public
In Java, you can create an abstract class that contains only abstract methods. On
How would one implement equals in a java-class which implements an interface that extends
I'm writing a Java class that's implementing an interface called Command, which contains the
In some old Java code, I found a class that contains a lot of
Java Method Class and Java 7's MethodHandle Class both refer to objects that are
The Java specification for the java.lang.Cloneable interface defines itself as signifying that any object
I have a Java project that needs a addon interface. I was thinking about
I am learning Java and just found that the Interface can have fields, which
I have an xsd (for basecamp xml) that contains <xsd:complexType name=ProjectType> <xsd:sequence> <xsd:element name=announcement

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.