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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:53:35+00:00 2026-06-09T11:53:35+00:00

As the title presumes, how do I this in Java? What im trying to

  • 0

As the title presumes, how do I this in Java? What im trying to do is something like this

first there is a class

public class MyFirstModel() {

    //standard constructor
    public MyFirstModel(){
            //some lines of codes
    }

    //A method
    public String getvalue() {

            //do something then
            return result;
    }
}

And the second Model(class)

public class MySecondModel() {

    //standard constructor
    public MySecondModel(){
            //some lines of codes
    }

    //A method
    public String getvalue() {

            //do something then
            return result;
    }
}

Having those two, sample, models i want to pass a class depending on the, action. Let’s just say there are two buttons and the first button is for the model and the second is for the second model. The third class that is to be pass to:

 FinalClass fclass = new FinalClass(<class here>);  <-- how do i pass the class here

Here, how do I pass the class? on the FinalClass, what would be its constructor? and how do I acces the methods of the passed class?

I hope you guys get what I mean. Please help.

  • 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-09T11:53:37+00:00Added an answer on June 9, 2026 at 11:53 am

    You don’t want to have both models implement an interface?

    MyModel.java:

    public interface MyModel {
        public String getValue();
    }
    

    MyFirstModel.java:

    public class MyFirstModel implements MyModel {
        public String getValue() {
            // stuff
        }
    }
    

    MySecondModel.java:

    public class MySecondModel implements MyModel {
        public String getValue() {
            // stuff
        }
    }
    

    CallingClass.java:

    public class CallingClass {
        private MyModel model = null;
        public CallingClass(MyModel model) {
            this.model = model;
        }
    }
    

    Then you can construct MyModel however you want and pass it in to CallingClass.

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

Sidebar

Related Questions

Title: Eclipse plug-in development Unable to instantiate class due to java.lang.NoClassDefFoundError: Trying to build
Title said it all. im just wandering if there something i can use in
It seems there is some padding around the title, which I can't figure out
Let's say we have a Collection of Items: class Item { public String title;
Title edits that reflect a better summary of the question are welcome. I'd like
Title said it all. Some context: I got a search mechanism - search view,
Title pretty much sums it up. Is there a technical name given to a
Title is quite self explanatory, but I have some animation being done in a
Title is most of the question, what allows this to be valid code? Is
Title pretty much explains most of my question. I will provide some context. I've

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.