...

View Full Version : Scope for abstract data types?



Marcuss
03-05-2008, 03:39 PM
Hey there, i'm relativly new to programming in general so my apologies if this is trivial.. I did try to find an answer via searching, but i didn't happen across anything satisfactory.

I'm currently implementing a structure of abstract data types with the idea of them being linked to eachother via arrays. The problem i'm having is that while i can manipulate a data type in the method it was created, it's not recognized in another method. eg :


class Yarr{

public void Yarr(){

Abstract a1 = new Abstract();

yarr2();

}

public void yarr2(){

a1.useSomeMethod();

}
}

Will result in the compiler telling me that the symbol a1 cannot be seen. The data type class file is declared as public, as is the method i'm trying to access within it.. So i'd assume it'd be visible no matter where you try to look at an instance from. Like i say i'm a little new, so i may be missing something trivial here.

Thanks in advance for any help.

-Marcus

sobrien79
03-05-2008, 10:59 PM
class Yarr {

private Abstract a1;

public void Yarr(){
this.a1 = new Abstract();
yarr2();
}

public void yarr2(){
this.a1.useSomeMethod();
}
}

Marcuss
03-06-2008, 04:48 PM
Thankyou, i understand why that works.

-Marcuss



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum