May be it could be silly,but I want to clear my the technical understanding of this code:
import netscape.*;//ldap jar
public class A {
public void method() {
...
try {
//code is written here.
LDAPSearchResults lsr = ldi.search(LDAPConnectionInfo.MY_SEARCHBASE,LDAPConnectionInfo.MY_SCOPE,LDAPConnectionInfo.MY_FILTER,null,false);
while(lsr.hasMoreElements()){
LDAPEntry findEntry = (LDAPEntry)lsr.nextElement();
} catch(...) {
}
}
}
Now I call another class
public class B {
A a = new A();
//here I want to use attributeName
}
- How could I access A class’s member(in try block) in B class.
- Any way to handle try block code for reuse in another class.
- How could I handle all those exception in another class.
Any modification should I need…
Calling method of Object type.
public class C{
private String attributeName;
public String getAttributeName() {
return attributeName;
}
public Object method(){
attributeName=lAttribute.getName();
}
}
- How could print this Object type method into String(in a jsp page)… any inputs
You’ll need a member in class
Aand a getter:Then:
There’s no way to access a method’s private variables like you did in the original example, as they only exist on the stack during the method call.
Edit: I noticed another question:
I assume you want to call your method somewhere else and catch the exceptions there. In that case you can use the
throwskeyword to communicate that your method will pass exceptions to the caller:then if some other piece of code calls
methodit will be forced to either handle or further propagate the exception.