Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Threaded View

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Object array with constructor

    I have a class project that requires a Symbol array. The parameters are:

    Symbol class with constructor and methods equals and toString and a TestDriver class that declares the Symbol array and main. Here's what I have:
    public class Symbol {
    private String inputSymbol; //Instance variable
     
        public Symbol(String sym){
            inputSymbol = sym;
        }
     
        public boolean equals(Symbol sym){
            return false;
        }
     
        public String toString(){
        }

    public class TestSymbols {
     
    public static void main(String[] args) throws IOException {
    Symbol[] sym = new Symbol[100];
     
    sym[0] = new Symbol("Katie");
    String tempText = sym[0].toString();
    System.out.println(sym[0]);
    System.out.println(tempText);
     
    System.exit(0); //end program
     
    }
     
    }

    The print statements are always null. What am I doing wrong that I cannot populate/access sym? How do I add and read an element at sym [i]?

    Thanks for your halp.
    Last edited by helloworld922; September 8th, 2010 at 03:17 PM.


Similar Threads

  1. 2D Object makes my object smaller, Why?
    By MassiveResponse in forum What's Wrong With My Code?
    Replies: 2
    Last Post: May 15th, 2010, 02:33 PM
  2. Array object and constructors
    By TarunN in forum Collections and Generics
    Replies: 14
    Last Post: May 6th, 2010, 04:04 PM
  3. How do you set an object in array to null value?
    By Arius in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 25th, 2010, 03:50 AM
  4. Private Constructor
    By Ganezan in forum Object Oriented Programming
    Replies: 4
    Last Post: November 7th, 2009, 04:02 PM
  5. Object array to int array?
    By rsala004 in forum Collections and Generics
    Replies: 1
    Last Post: October 30th, 2009, 04:09 AM