Results 1 to 5 of 5
Thread: multi-line construction.
- 05-04-2011, 08:27 PM #1
Member
- Join Date
- May 2011
- Posts
- 2
- Rep Power
- 0
multi-line construction.
So it's been awhile for me on java, I've been stuck in c++ for awhile, but i'm trying to remember how java would naturally solve this.
so lets say i have class called City with a getter that returns the name of the city in string form.
I can initialize that by saying
If I remember correctly though I can also do it this way..Java Code:City my_city = new City("New York"); system.out(my_city.name());
but what would happen if I did this...?Java Code:City my_city; my_city = new City("New York"); system.out(my_city.name());
would an error get thrown or would it just print a blank string?Java Code:City my_city; system.out(my_city.name());
- 05-04-2011, 08:38 PM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
A null pointer exception will get thrown when you attempt to call a method on an uninitialized object reference.
- 05-04-2011, 08:39 PM #3
Member
- Join Date
- Jan 2011
- Posts
- 67
- Rep Power
- 0
You'd get an error because my_city has not been initialized.
Currently developing Cave Dwellers, a Dwarf Fortress/Minecraft style game for Android.
- 05-04-2011, 08:47 PM #4
Member
- Join Date
- May 2011
- Posts
- 2
- Rep Power
- 0
ok so what if I did this...
can I assume the initialization of the new City would also throw that error since state isn't initialized?Java Code:State my_state; //my_state = new State("NY"); City my_city; my_city = new City(my_state, "New York");
Also would that be a run time or a compile time error?
- 05-05-2011, 01:20 AM #5
Similar Threads
-
Formatting java command line output - Multi line string
By dricco in forum New To JavaReplies: 2Last Post: 07-02-2010, 02:20 PM -
Multi Valued Command Line arguments
By joey86 in forum Advanced JavaReplies: 9Last Post: 01-08-2010, 12:07 AM -
AVL-tree construction
By student89 in forum Advanced JavaReplies: 0Last Post: 10-27-2008, 05:33 AM -
Multi-line Tooltip inside a JTable's Cell
By stevenc49 in forum AWT / SwingReplies: 2Last Post: 06-29-2008, 04:15 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks