Results 1 to 2 of 2
  1. #1
    Shyam Singh is offline Member
    Join Date
    Jun 2008
    Rep Power

    Question [SOLVED] Unable to access array defiened in constructor in other methods.

    /* taking user i/p for row & column size of an array..

    * using constructor to collect the value which i m passing from main method

    * i m type casting the i/p taken in main using Scanner class .

    * Problem -->> unable to access the stud array in other methods .


    import java.util.Scanner;

    class inuser {

    public inuser(int r,int c) {

    int stud[][] = new int[r][c];

    for(int x=0;x<r;x++) {

    for(int y=0;y<c;y++) {

    int mul=(x+1)*(y+1);
    } // constructor closed

    public void dispaly(int r,int c) {

    for(int x=0;x<r;x++) {
    for(int y=0;y<c;y++) {


    public static void main(String args[]) throws IOException {

    System.out.println("enter row value");

    Scanner s=new Scanner(;

    int r=s.nextInt();

    System.out.println("entred value ="+r);
    System.out.println("enter Column value");

    int c=s.nextInt();
    System.out.println("entred value ="+c);
    inuser in=new inuser(r,c);


  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power


    stud can NOT be reached from other methods because it is only defined inside the inuser constructor. Move its definition outside the constructor and the other methods will be able to see it.
    You can still do the initialization in the constructor.

Similar Threads

  1. Array Constructor
    By Javanoob828282 in forum New To Java
    Replies: 1
    Last Post: 04-30-2008, 11:25 PM
  2. Replies: 0
    Last Post: 12-19-2007, 10:10 AM
  3. Replies: 0
    Last Post: 12-19-2007, 10:01 AM
  4. Replies: 1
    Last Post: 12-14-2007, 08:25 AM
  5. How to access array stored in database through JSTL
    By saurabh.joshi in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 11-19-2007, 02:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts