Results 1 to 2 of 2
  1. #1
    BookOfEliX is offline Member
    Join Date
    Feb 2015
    Posts
    20
    Rep Power
    0

    Default Need help understanding objects and classes!!

    I have recently start learning about objects and classes in java. I understand that in order to use multiple classes in one file you need one class to be public and the rest are private. But after that I don't understand how to invoke the private class in the public class. I thought if I tried programming on my own I can have a better understanding of it, but had no success.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    14

    Default Re: Need help understanding objects and classes!!

    Quote Originally Posted by BookOfEliX View Post
    I understand that in order to use multiple classes in one file you need one class to be public and the rest are private.
    Well, that is not correct. First, only inner classes can be declared private. None of the classes in a file need to be public (even the one with main). It can be package private which means leaving off the access modifier. But the other classes can be declared in the same file as well. Public classes must be in their own file named MyClass.java where MyClass is the name of the public class. Making them public makes them accessible by all programmers who wish to use the class. You can read about access modifiers in the Java tutorials. You can also read about inner classes and how to invoke them as well as other subtleties of class creation.

    Regards,
    Jim
    Last edited by jim829; 03-01-2015 at 11:02 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Am I understanding classes correctly?
    By nakkim in forum New To Java
    Replies: 2
    Last Post: 02-13-2014, 11:07 PM
  2. Understanding CMD and Classes?
    By fahman_khan75@yahoo.com in forum New To Java
    Replies: 3
    Last Post: 01-23-2014, 12:52 PM
  3. Problem with understanding the use of classes
    By Robomano in forum New To Java
    Replies: 4
    Last Post: 12-10-2012, 11:45 AM
  4. Replies: 2
    Last Post: 01-22-2012, 11:50 PM
  5. Trouble understanding objects
    By cagipple in forum New To Java
    Replies: 1
    Last Post: 10-03-2011, 09:47 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •