Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: How can combing two classes together be made possible?

  1. #1
    Junior Member
    Join Date
    Dec 2021
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default How can combing two classes together be made possible?

    i have two working classes which I've saved on two different files, but I want to combine the code into one file.

    One class is where I obtain general information from a user/customer
    The second class is where I take their more personal details i.e home address

    I want to keep the two areas of information separate.

    I will want to encrypt the data as well, can I do this via code both in idle mode and in transit mode using Java and how can I go about this?

    I am new to Java somewhat, was stuying it 12 years ago when I was at Uni, but later gave up as I decided to pursue another career, but now I am back, made a lot of mistakes in my life and I need to get on the road to making some serious money and I think becoming moderately decent at it, if not one of the best will help me. Rome wasn't built in a day and I am fully aware of that. It might take me 5 years or longer if I keep at it, but I hope I'll get it earlier and I can start applying for some jobs.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: How can combing two classes together be made possible?

    A file can contain the code for more than one class. But only one of the classes can be public and its name must match the filename
    Often the code in two classes can be merged by copying the methods and variables from each class into the new merged class.
    A problem might be if there are methods with the same name or variables with the same name.
    Then there will be problems with all the other classes that use any of the methods of either class.

    Why do you want to merge the two classes into a single class? That is going the wrong way. It is more often to have code in one large class be migrated to separate, smaller classes.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    PowerplayCode27 (December 20th, 2021)

  4. #3
    Junior Member
    Join Date
    Dec 2021
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: How can combing two classes together be made possible?

    Hi, thank you for your rapid response, that explanation of public/private classes rings a bell.

    I am right back at the learning stage, so I will often be asking questions on approaches, which might be completely insane to the experienced programmer.

    I like what you did there, answered the question followed by recommending a different approach (the correct one! ha), that is exactly the kind of answers I am looking for, so I can gain varied knowledge of how I can make my idea come to life followed by the correct approach to take.

    --- Update ---

    Quote Originally Posted by Norm View Post
    A file can contain the code for more than one class. But only one of the classes can be public and its name must match the filename
    Often the code in two classes can be merged by copying the methods and variables from each class into the new merged class.
    Can you please give me an example of how I can go about this? In your own time of course.

    In the meantime will be playing around with other ideas.

Similar Threads

  1. Replies: 2
    Last Post: July 11th, 2014, 03:02 AM
  2. Replies: 1
    Last Post: July 11th, 2014, 02:01 AM
  3. Classes of classes? [Very beginner asking a question] [w/ Codes]
    By UhKindaAwkward in forum Object Oriented Programming
    Replies: 6
    Last Post: December 24th, 2013, 03:05 AM
  4. [SOLVED] Combing println with for loop
    By norske_lab in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 25th, 2012, 01:15 PM
  5. Combing/Decoding MPEG and Other Video Format?
    By MrFish in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: September 5th, 2011, 08:21 AM