Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Java noob

Name: Anonymous 2008-02-10 15:34

Ok so im in my second semester of comp science, the first semester I learned the basics of C++ and I loved it. However this semester I'm learning Java and it just isn't coming together for me so I have some questions about it.(sorry for the noobness)

1. What are constructors for? I understand that when I create a new object the constructor is "new" but I don't get when I need to use them.

2. What's the whole deal with the "public" and "private" in front of a class or method, in what situations should something be private or public?

3. When declaring variables I'm confused about when I should declare varialbes in the main method or in some other method. Also when are variables declared under the main class?

Thank you

Name: Anonymous 2008-02-10 16:10

1. A constructor is called automatically evertime you initialise something. So each time something is created you want a method to run put it in your constructor. Try a real world example, will make this more obvious.

2. Scope java.sun.com and read all there is,

3. See 2, this is all about scope. Some variables are only available at certain points in your code.

I fail to believe you were even average at c++ if you fail to understand these very simple concepts.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List