Java Question

This is a discussion on Java Question within the A Brief History of Cprogramming.com forums, part of the Community Boards category; In Java, you have to use the following notation for declaring instances of user-defined classes (I know this is blatently ...

  1. #1
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913

    Java Question

    In Java, you have to use the following notation for declaring instances of user-defined classes (I know this is blatently obvious if you know Java, but I'm just setting my self up for my point. It seems like I don't have one, I know, but I do):

    class_type object_name = new class_type(constructor_parameter)

    The book I'm using tells me that to declare arrays of user defined classes, you use the following notation:

    class_type[] array_name = new class_type[array_size];

    My question is this: where do the constructor parameters go? And how do you declare arrays of the primitive data types (i.e. int, etc.)? <- OK, THERE'S my point!

    Thanks in advance if you can help.

    _______________________
    Sean Mackrory
    sean_mackrory@hotmail.com

  2. #2
    junior member mix0matt's Avatar
    Join Date
    Aug 2001
    Posts
    144

    java master?

    jk, i'm not a java master. I'm just learning the larguage. it seems really interesting, though

    to answer you're main "point" concerning the array of primitive types:

    Code:
    int[] array = new int[100];    // or...
    int array2[] = new int [100];
    it could go either way....

    as f0r your first question, "where do the constructor parameters go". i don't really know. my guess is that it is similar to C++ in that the default constructor will be used.
    THIS IS NOT JUST A CHRONICLING OF THINGS WE HAVE DONE IN THE PAST BUT OUR RISE TO POWER.

  3. #3
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    Code:
    public class whatever {
        int data;
        whatever(int i) {
           data = i;
         }
         public static void main(String[] args) {
                /* no actual whatevers created yet, whatever[0] to
                    whatever[9] contain null references, but whateverlist is 
                    not null */
                whatever[] whateverlist = new whatever[10]; 
                for (int i = 0; i < 10; i++) {
                      whateverlist[i] = new whatever(i*i); // create individual whatevers here
               }
         }   
    }
    Last edited by SilentStrike; 12-04-2001 at 01:04 AM.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mats, the java answers
    By Jaqui in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 04-22-2008, 03:12 AM
  2. Java vs C to make an OS
    By WOP in forum Tech Board
    Replies: 59
    Last Post: 05-27-2007, 04:56 AM
  3. Windows GDI vs. Java Graphics
    By Perspective in forum Windows Programming
    Replies: 7
    Last Post: 05-07-2007, 11:05 AM
  4. How to use Java with C++
    By Arrow Mk 84 in forum C++ Programming
    Replies: 2
    Last Post: 02-27-2003, 04:12 PM
  5. A question for .. java!
    By McAuriel in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 12-01-2002, 11:16 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21