• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

fetch values from one package into another package

 
muthu bharathi
Ranch Hand
Posts: 97
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I've one package, with in this package i've one method. in this method i've one variable just like below

package XXX;
public class schema
{
public void validateschema
{
boolean verror;

}
}
i want to fetch the variable "verror" in to my another package...

please help me...

--
with thanks
M. Bharathi
 
Senthil Kumar
Greenhorn
Posts: 21
Chrome Eclipse IDE Firefox Browser
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
package test1;
public class Schema
{
public boolean validateSchema()
{
boolean verror;
statements;
return verror;
}
}


In your next package, say for example test2,

import the package test1 and access the validateSchema() by creating the Object of that Class(Schema) , now you can get the value verror.
 
muthu bharathi
Ranch Hand
Posts: 97
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi senthil,


ok. i need the syntax in java


--
with regards
M. bharathi
 
Senthil Kumar
Greenhorn
Posts: 21
Chrome Eclipse IDE Firefox Browser
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the Syntax.

pack pack1;
class ClassName{

public datatype method(){

statements;
return datatype;
}
}

pack pack2;

import pack1.*;

class ClassName2 {

public static void main(String arg[]){

ClassName object = new ClassName();
datatype var1 = object.method();

}
}
 
muthu bharathi
Ranch Hand
Posts: 97
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi senthil,


thanks a lot... now i've another doubt

package xxxx
class schema
{
public void method1()
{
boolean validation;
}
}
i want to access the variable "validation" from main program

--
with regards,
M. bharathi
 
Senthil Kumar
Greenhorn
Posts: 21
Chrome Eclipse IDE Firefox Browser
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
package xxxx
class schema
{
public void method1()
{
boolean validation;
}
}

validation is a local variable, so you cannot access this in your main method. better use validation as Instance Variable.

 
Campbell Ritchie
Sheriff
Pie
Posts: 47300
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Better still to provide a predicate method which returns the validation boolean value.
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12022
25
Chrome Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
muthu bharathi wrote:I've one package, with in this package i've one method.

Actually, you have one package, and in that package, you have one CLASS, and in that CLASS, you have one method. In that method, you have a variable.

and here's the key thing... that variable only exists inside that method. Even if you create an object of type Schema (and class names should have their first letter capitalized), unless you are running that method, it doesn't make sense to talk about getting that value.

 
muthu bharathi
Ranch Hand
Posts: 97
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

i've got it.. thanks a lot.


--
With thanks,
M. Bharathi
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic