Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-20-2008, 04:09 PM
Member
 
Join Date: Jun 2008
Posts: 46
Shyam Singh is on a distinguished road
[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.io.*;
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);
stud[x][y]=mul;
}
}
} // constructor closed

public void dispaly(int r,int c) {

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

System.out.print("\t"+stud[x][y]);
}
System.out.println("");
}
}

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

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

Scanner s=new Scanner(System.in);

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);
in.display(r,c);

}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-20-2008, 06:42 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Array Constructor Javanoob828282 New To Java 1 05-01-2008 12:25 AM
Calling constructor of parent class from a constructor Java Tip Java Tips 0 12-19-2007 11:10 AM
Calling constructor of same class from a constructor Java Tip Java Tips 0 12-19-2007 11:01 AM
problems with asigning elements of an array to a constructor rednessc New To Java 1 12-14-2007 09:25 AM
How to access array stored in database through JSTL saurabh.joshi JavaServer Pages (JSP) and JSTL 1 11-19-2007 03:46 AM


All times are GMT +3. The time now is 02:18 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org