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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:09:47+00:00 2026-05-28T03:09:47+00:00

I’m quite new to Java and am stuck with this, please. Well I know

  • 0

I’m quite new to Java and am stuck with this, please.
Well I know that an interface ‘provides’ only abstract methods to be implemented by the concrete subclasses. Hope this is true (at least).
So I was studying a sample code of jxl api, to write and read an excel file, and I arrived to this point:

workbook = Workbook.createWorkbook(new File("/home/me/workspace/files/output.xls"));
WritableSheet sheet = workbook.createSheet("first sheet", 0);

That is, the workbook object was previously instantiated and is a WritableWorkbook object.
I’m creating the workbook using the static method provided by Workbook that is a superclass of WritableWorkbook. And until this, I’m there.
But, then, what am I doing in the second instruction?
The sheet is a “WritableSheet”, but this is an interface! And seeing the api, there are no implementing classes. And “WritableSheet” is a subinterface of another interface, which is “Sheet”. Both interfaces. But, I thought that I wasn’t able to create an object from an interface. While, then, using the createSheet method (provided by WritableWorkbook), it seems I’m creating a WritableSheet.
Then in the sample code I arrive to this:

Label lblNome = new Label(0, 1, "Nome:");
sheet.addCell(lblNome);

No problem the first line, I create a new element, a label (that is a text cell);
but the second? again, addCell is a interface method seeing the api!
while sheet was the previous implementation of what? Of an interface seems to me.
And which method they are using, if interfaces provide abstract method?

Please would you clarify me that? At the end the code works, but it’s not clear how those interfaces (Sheet and WritableSheet) are working.

Thank you

  • 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-28T03:09:47+00:00Added an answer on May 28, 2026 at 3:09 am

    Interfaces in Java are defining a contract and they’re types! There may be several classes signing this contract – we say these classes are implementing the interface.

    You can see any object created by a class that signed a contract as an object of this contract. It can be casted to the contract – we say you can cast any object from a class implementing an interface to this interface type.

    The static factory method createSheet() is doing sth like that. It is internally using a concrete class that is implementing WritableSheet and returning an object of it. Since createSheet()‘s return type is WritableSheet it is casted to the type WritableSheet. Be sure to comprehend that we did not create an object of WritableSheet – we cannot since it is an interface. But we can cast an object of any class implementing the interface to the type WritableSheet.

    One major advantage is that the implementation used internally by createSheet() can be changed silently without affecting client code that uses it. When createSheet() switches over to another implementation that implements WritableSheet then you do not have to change anything in your client code!

    Your code relies on a contract defined by the interface rather than a concrete implementation. And that’s good!

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I want use html5's new tag to play a wav file (currently only supported
Does anyone know how can I replace this 2 symbol below from the string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

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.