Results 1 to 6 of 6
Thread: Ok I have a few questions.
- 07-28-2012, 06:21 PM #1
Member
- Join Date
- Jul 2012
- Posts
- 6
- Rep Power
- 0
Ok I have a few questions.
I've been Reading Core Java Programming by Cay S. Horstman and Gary Cornell. I have to say that the chapter on Object Oriented Programming is somewhat vague.
1.) My first question is why do you need to construct an object? I've seen code be run directly from a class, so why do you need to instantiate an object.
2.) My second question is where is an object instantiated? Does it get instantiated inside a class or does it get instantiated outside of the class.
3.) My third question is can you show me how the basic structure of an object being instantiated from a class looks like? With all the code needed to compile and run the example.
4.) My fourth question is what does a constructor look like versus a method. Assuming the model looks like the following
{
constructor
constructor
...
method
method
...
instance field
instance field
...
I know that you might tell me to just do a google search, but I've tried googling these questions and I didn't come up with answers. In my book there are many snippets of code, but not very many full examples that the developer can create.
- 07-28-2012, 06:41 PM #2
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 1
Re: Ok I have a few questions.
Thankfully, Oracle has anticipated some of these questions:
1. What Is an Object? (The Java™ Tutorials > Learning the Java Language > Object-Oriented Programming Concepts)
2. An object is instantiated inside a class. You can instantiate the object when you define a variable:
...or you can define a variable and instantiate its object later inside a method:Java Code:String word = "hello";
3.Creating Objects (The Java™ Tutorials > Learning the Java Language > Classes and Objects) (There is a workable demo that you can download).Java Code:String word; ... public static void main(String[] args) { word = "hello"; }
4. What a constructor looks like: Providing Constructors for Your Classes (The Java™ Tutorials > Learning the Java Language > Classes and Objects) What a standard method looks like: Defining Methods (The Java™ Tutorials > Learning the Java Language > Classes and Objects)Last edited by awinston; 07-28-2012 at 07:02 PM. Reason: clarification
"Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill
-
Re: Ok I have a few questions.
- 07-28-2012, 09:27 PM #4
Student
- Join Date
- Jul 2012
- Location
- United States
- Posts
- 328
- Rep Power
- 1
Re: Ok I have a few questions.
"Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill
- 07-28-2012, 09:51 PM #5
Re: Ok I have a few questions.
brocksoffice, please go through the Forum Rules -- particularly the third paragraph.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 07-29-2012, 02:47 AM #6
Member
- Join Date
- Jul 2012
- Posts
- 6
- Rep Power
- 0
Similar Threads
-
3 questions
By silverglade in forum New To JavaReplies: 11Last Post: 05-09-2011, 03:17 PM -
I have 2 questions =P
By santa in forum New To JavaReplies: 4Last Post: 01-19-2011, 05:35 PM -
Questions
By Csharks in forum New To JavaReplies: 8Last Post: 01-19-2011, 04:11 AM -
Questions About JSP?
By mtz1406 in forum JavaServer Pages (JSP) and JSTLReplies: 2Last Post: 08-19-2008, 07:56 PM -
Just a Few Questions
By pringle in forum New To JavaReplies: 21Last Post: 01-09-2008, 06:21 PM


3Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks