Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8445429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:39:27+00:00 2026-06-10T09:39:27+00:00

May be it could be silly,but I want to clear my the technical understanding

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:39:28+00:00Added an answer on June 10, 2026 at 9:39 am

    You’ll need a member in class A and a getter:

    public class A {
       private String attributeName;
    
       public String getAttributeName() {
           return attributeName;
       }
    
       public void method(){
            ...
    
            try {
                //code is written here.
                attributeName = lAttribute.getName(); 
            }
            catch() { 
            } 
       } 
    }
    

    Then:

    public class B {
        A a = new A();
    
        // somewhere
        String str = a.getAttributeName();
    }
    

    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:

    How could I handle all those exception in another class.

    I assume you want to call your method somewhere else and catch the exceptions there. In that case you can use the throws keyword to communicate that your method will pass exceptions to the caller:

    public class A {
    
        public void method() throws IOException {
    
            //code is written here.
            String attributeName = lAttribute.getName(); 
        } 
    
        public void anotherMethod() {
            try {
                method();
            } catch(IOException ex) {
                ...
            } 
        }
    }
    

    then if some other piece of code calls method it will be forced to either handle or further propagate the exception.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I may be missing something obvious here, but how could I rewrite this code
This may be a silly question, but could someone please provide a standard reference
Well, may be this question is silly, but I couldn't find a way (except
This may be a silly question but... Say you have a sentence like: The
Can a String hold Array Object? May be this question could be silly? Just
This may seem a silly question, but having been pondering it for a few
This may be a silly question - but I couldn't find out how to
Now, this may be a silly question but sometimes the terms Framework and API
Okay this may sound silly, but I am not very familiar with XML. What
Okay, this may be a silly question but I'm still on my path to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.