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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:31:31+00:00 2026-05-25T01:31:31+00:00

Apologies if my terminology is incorrect, I have only started Java (and OO programming

  • 0

Apologies if my terminology is incorrect, I have only started Java (and OO programming in general) 6 weeks ago.

A homework assignment has given me an interface class:

public interface Example {
    void Function();
    //etc
}

And then I have a couple of classes that “implement” that interface class, eg:

public class myExample1 implements Example {
    void Function(){ stuff;}
    public void myExclusiveFunction() { stuff;}
        ...
}

Inside the myExample1 class, I define the functions inside Example, but also add some specific functions to the myExample1 class.

In my main program, I have created a LinkedList<Example> eList = new LinkedList<Example>. Inside that Linked List, I am storing multiple types of Examples (myExample1, myExample2, etc). I want to do something like:

eList.get(i).myExclusiveFunction();

However this will not work. The compiler tells me:

The method myExclusiveFunction() is undefined for the type Example.

How can I use this function? I really want to have the LinkedList be able to hold objects of any Example subclass, and I am under an assignment restriction to NOT edit the Example interface.

  • 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-25T01:31:32+00:00Added an answer on May 25, 2026 at 1:31 am

    Well you have 2 options:

    1 – Change your LinkedList to store myExample1 instead of Example.

    LinkedList<myExample1> eList
    

    2 – Use instanceof and cast the class to the type myExample1 (messy).

     Example exObj = eList.get(i);
     if (exObj instance of myExample1) {
         ((myExample1)exObj).myExclusiveFunction();
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I apologize if I use the incorrect terminology here, I've only been using emacs
My apologies if I am using the incorrect terminology, as I'm a bit of
Apologies if this question has been asked already, but suppose we have this code
Apologies if I get the terminology wrong. How do I define a constraint in
Apologies if I've got the terminology wrong here—I can't think what this particular idiom
Apologies in advance for the long-winded question. I'm really a database programmer, but have
Apologies if this is too ignorant a question or has been asked before. A
I'm new to programming and apologize up front if I misuse terminology. In a
Apologies if this has been asked already. I've seen answers regarding static SQLs, but
Apologies if my terminology is off, I'm new to C#. I'm trying to use

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.