And hopefully i understand this. In the next class he made an Account object named my_account by calling the constructor Account() and then changed the double amount by calling some methods -"my_account.method().
But here's my question. He made the Account class and he made the AccountDemo main class. How does the AccountDemo know the Account class information without ever importing the Account class? Does it automatically know if its in the same folder or directory, or are you supposed to import it?
Thanks and God Bless you helping people.
Matthew 1:23 - "Behold, the virgin shall be with child, and bear a Son, and they shall call His name Immanuel," which is translated, "God with us."
Merry Christmas (or Happy Holidays) and God Bless you all.
John Simer wrote:yes I do know about packages.
At the top of the code on both of them, wouldn't you have to put
Or do you just never have to say what package it is in?
God Bless you, the Lord Jesus has great plans for you
because you did not specify a package, your classes get associated with the default package.
All classes in the default package are able to see each other as you have it defined.
How does the AccountDemo know the Account class information without ever importing the Account class?
Great question! Import statements are not what makes a class available to your program, they just make it possible for you to use the class's short name. The classpath is what makes a class available. If the com.acme.Monkey class is in the classpath, you can say
com.acme.Monkey curious = new com.acme.Monkey();
but if you import com.acme.Monkey you can say
Monkey curious = new Monkey();
and the compiler will know what you mean (unless there's another Monkey class somewhere). The compiler still records it using the full classname.