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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:21:07+00:00 2026-05-26T07:21:07+00:00

I have a class file that is setup similar to the structure below. Basically

  • 0

I have a class file that is setup similar to the structure below. Basically objALLData is my main data object (it collects the information from the user and inserts it into the DB).
However, in objAllData I have a need to have the option of a collection of objSubSet1 and/or objSubSet2. However, both of these subsets do not need to be public. All I need them to do is to populate and then in the objAllData I would add them to a collection (specified in objAllData).

When I try to make the subset classes private I was getting an inconsistent accessibility error. According to my research I needed to make them public. However, I really don’t want anyone to know about these objects except objAllData. Does that make sense?

Any idea on how I can achieve what I think I want? 🙂

public class objAllData
{

     List<objSubSet1> ss1 = new List<objSubSet1>();
     List<objSubSet2> ss2 = new List<objSubSet2>();

     public List<objSubSet1> addSS1toCollection()
     {
         objSubSet1 myOBJSS1 = new objSubSet1();
         myOBJSS1.property = "";

         ss1.add(myOBJSS1);
         return ss1;
      }

}

public class objSubSet1
{
    <property>
    <property>
    <property>
}

public class objSubSet2
{
     <property>
     <property>
     <property>
}
  • 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-26T07:21:07+00:00Added an answer on May 26, 2026 at 7:21 am

    Since your add method returns the list, the user needs to have some visibility to the type you are returning. The easiest way to not fully expose the real object type is to create an interface.

    public interface Thing {
      //public methods
    }
    
    public class ObjAllData {
      public List<Thing> addSS1toCollection() {
        List<ObjSubSet1> ss1 = new List<objSubSet1>();
        ss1.add(new ObjSubSet1());
        return ss1;
      }
    
      private class ObjSubSet1 : Thing {
        //implements public methods
      }
    }
    

    This way the user only has access to the methods defined by Thing where as ObjAllData has full access to the real object type.

    NOTE:
    Your sample code has a number of syntax errors that will keep your code from compiling.

    Class definitions do not have parenthesis in them

    public class objAllData() //incorrect
    public class ObjAllData //correct
    

    Function definitions have to specify the variable type they are returning, not the variable name.

    public ss1 addSS1toCollection() //incorrect
    public List<objSubSet1> addSS1toCollection() //correct
    

    You are also missing a semi-colon after your return statement.

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

Sidebar

Related Questions

I have a class file that contains all the classes that are needed for
I have a class that parses very large file (that can't fit in memory)
I have a file that stores exam scores for a class of students. I
I have an actionscript file that defines a class that I would like to
I have a class that occasionally gets passed null for File objects. During normal
I have this class called PollFrame that extends JFrame in a file called PollFrame.java
I have a C# class method that return a xml document not file. How
I have a helper class pulling a string from an XML file. That string
I have a page base class that has no .aspx file and so I
I have a Java program that opens a file using the RandomAccessFile class. I'd

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.