View Single Post
  #3 (permalink)  
Old 09-12-2008, 10:30 AM
fishtoprecords's Avatar
fishtoprecords fishtoprecords is offline
Senior Member
 
Join Date: Jun 2008
Posts: 522
fishtoprecords is on a distinguished road
Quote:
Originally Posted by ChazZeromus View Post
4) When exactly when you would use the new keyword? I know that in C++ new is allocates memory so that a pointer can point to the new memory, but I notice that java does not have any pointer facilitation.
First, your topic/thread title is meaningless. You really should pick a meaningful title, as it will encourage folks to answer it.

One critical difference between Java and C (and assembler languages) that that you never use pointers. You can not do pointer arithmetic. There are no expresions that yield a pointer that you can do anything with.

The line:
Code:
MyObject myObj = new MyObject():
creates an instance of a MyObject() object, and the variable "myObj" is a reference to it. The reference works much like a C++ reference, and the syntax here is exactly what it is in C++. But it is illegal and illogical to do something like:
Code:
myObj++;
in Java, whereas it is fine in C++.
Reply With Quote