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 5 of 5

Thread: Where to put objects and methods

  1. #1
    Junior Member
    Join Date
    Oct 2018
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Where to put objects and methods

    I want to make a plan for example to the grocery store, and I open 2 classes one for product ,and the other for customers,
    A.Where should I put the object(the customers and the products)? in the main? in their class?
    B. Where should I put the methods like buy?
    (I started to learn programming a month ago, so if possible a basic answer (not deep ..))

  2. #2
    Member
    Join Date
    Sep 2018
    Location
    Virginia
    Posts
    284
    My Mood
    Cool
    Thanks
    0
    Thanked 38 Times in 36 Posts

    Default Re: Where to put objects and methods

    The way to think about something like this is to model the real world. Customers buy products from stores. So one possibility is have a grocery store class return an instance of whatever product is being bought by the customer.

    Regards,
    Jim

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

    YehudaNevo (October 15th, 2018)

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

    Default Re: Where to put objects and methods

    thenks

  5. #4
    Junior Member
    Join Date
    Sep 2017
    Location
    South Africa
    Posts
    12
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: Where to put objects and methods

    a class defines the needed information. The class is the blueprint. All classes create objects, and all objects contain characteristics.

  6. #5
    Member
    Join Date
    Sep 2018
    Location
    Virginia
    Posts
    284
    My Mood
    Cool
    Thanks
    0
    Thanked 38 Times in 36 Posts

    Default Re: Where to put objects and methods

    Quote Originally Posted by arminius View Post
    a class defines the needed information. The class is the blueprint. All classes create objects, and all objects contain characteristics.
    Not quite. Some classes cannot be instantiated and therefore don't create objects. One such example is the java.lang.Math class which contains only static methods. And as such, it does not have any inherent characteristics that an instantiable class might have.

    Regards,
    Jim

Similar Threads

  1. [SOLVED] Beginner: Passing Objects to Methods
    By free_spirit in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 9th, 2018, 01:39 PM
  2. Creating new objects within methods
    By Blykon in forum What's Wrong With My Code?
    Replies: 5
    Last Post: September 14th, 2014, 11:37 PM
  3. Creating objects from methods
    By fahman_khan75@yahoo.com in forum What's Wrong With My Code?
    Replies: 7
    Last Post: March 21st, 2014, 12:00 PM
  4. [SOLVED] Help with objects, methods, and class inheritance.
    By Gingerbread Fetus in forum Object Oriented Programming
    Replies: 3
    Last Post: October 18th, 2013, 09:02 AM
  5. where to put list of objects method OOP
    By stanlj in forum Object Oriented Programming
    Replies: 3
    Last Post: January 14th, 2013, 01:08 PM