How to create an instance of a protected class outside the enclosing packag

Hi all,
I have a piece of code like this:
package test;
public class A {
protected class B { }
How to create an instance of B outside the package test ? Could you please give me an example ?
Thanks
Ha Chau

Thank WirajR for your reply, but in your solution,
you have to create an instance of B inside class A
and pass it outside. I would like to know whetherwe
can create an instance of class B outside thepackage
test. That means I want the instance creation
expression of B appears outside the package test.Can
we do that?
If you want to use a class this way then it shouldn't
be marked protected. I can't see why you don't
just declare it public if that's what it is.
Wouldn't be much point to haveing a protected
modifier if it had no effect, would there?I think there is use for it if you use an interface to filter out the parts you want to give public access to, and keep the part you want to keep protected, protected

Similar Messages

  • How to refer to a protected class outside the enclosing package

    Hi all,
    At the page 357 of the book Java Language Specification(Second Edition), when saying about checking accessibility of Type and Method, they concern Let C be the class containing the method invovation T.m, if T is in a different package than C, and T is protected then T is accessible if and only if C is a subclass of T. I just wonder how to refer a protected type outside the package it declared.
    For example,
    package test;
    public class test {
    static protected class protectedTest {
    public void foo() {..}
    in another package
    import test.*;
    class subtest extends test.protectedTest {  <- error
    Anyone can give me an example showing an invocation directly to foo() declared in class test.protectedTest ? The invocation should appear outside package test.
    Thanks,
    Ha Chau

    The protected inner class would be accesible only within a class which extends test, where you could either use or extend it as in:
    class subtest extends test {
        private static class sub2 extends protectedTest {
               }

  • How to create Multiple instances of This SingleTon class

    import java.io.*;
    import java.util.Properties;
    import java.net.URLEncoder;
    public class ddd
              // declaring variables
              static private ddd _instance;
              String connectIP;
              int connectPort;
              String systemID;
              String password;
         String systemType;
              // Constructor with arguments
              private ddd()
              globalInit();
         // method returning the ddd instance.
              public static      synchronized ddd getInstance()
              if (_instance == null)
                        _instance = new ddd();
              return _instance;
              // Global initialisations
              public void globalInit()
              systemID ="XXXXX" ;
              password ="XXXXX";
              systemType ="Null";
              public static void main(String[] args)
                   ddd sb;
                   sb = ddd.getInstance();
                   System.out.println(ddd.getInstance());

    Don't cross-post:
    http://forum.java.sun.com/thread.jsp?thread=547911&forum=54&message=2669925
    http://forum.java.sun.com/thread.jsp?thread=547912&forum=31&message=2669928
    Sorry, I can't help but think that this is one of the more foolish questions I've read in a while.
    The pattern Singleton means "I only want one of these in a single JVM". If you want multiple instances, or even a restricted number of instances, then rewrite the class (something like this):
    public class LimitedEdition
        public static final int MAX_EDITIONS = 3;
        private static int numEditions;
        public static void main(String [] args)
            try
                if (args.length > 0)
                    int numEditions = Integer.valueOf(args[0]).intValue();
                    for (int j = 0; j < numEditions; ++j)
                        LimitedEdition limited = new LimitedEdition();
                        System.out.println(limited);
            catch (Exception e)
                e.printStackTrace();
        public LimitedEdition() throws InstantiationException
            if (numEditions < MAX_EDITIONS)
                ++numEditions;
            else
                throw new InstantiationException("Only " + MAX_EDITIONS + " instances allowed");
        public String toString()
            return "[ instance # " + numEditions + "]";

  • How to create multiple instance on same database

    Hi ,
    I would like to know how to create multiple instance on same database . I know that some people use database configuration assistant to do this but i could not figure out how they did it.
    Any how if some one can help me with this and can give me links of this it would be great help for me.
    Thank you for reading my problem and helping me !
    Amil
    please if possible mail me on [email protected]

    How to create multiple instance?????Do you mean multiple instances on the same database, or multiple databases on the same machine ?
    I m new to this field....
    Willin to learn a lot about oracle....Then it wouldn't be bad reading a bit of Database Concepts

  • How to create an instance for RemoteSession without using create() method

    How to create an instance for RemoteSession without using create() method?

    What's RemoteSession? Not in the JDK. And does the question have anything to do with concurrency?

  • How to create an instance of the database

    No that won't work. I have to set it up independant from each other because I can't get to Uni until Monday and I want to have this done over the weekend really.
    The main issue seems to be now how to create an instance of the database

    To create a database:
    you first connect as internal (user) with the passeword 'oracle'
    the syntax is: connect internal/oracle
    You type in this script:
    STARTUP NOMOUNT PFILE=$PFILE
    CREATE DATABASE db01
    LOGFILE
    GROUP 1 ('c/oracle/oradata/db01/redo_01a.log',
    'c/oracle/oradata/db01/redo_01b.log'
    ) size 100k,
    GROUP 2 ('c/oracle/oradata/db01/redo_02a.log',
    'c/oracle/oradata/db01/redo_02b.log'
    ) size 100k
    MAXLOGFILES 32
    MAXLOGMEMBERS 2
    MAXLOGHISTORY 1
    DATAFILE 'c/oracle/oradata/db01/system01.dbf'
    size 7M
    MAXDATAFILES 254
    MAXINSTANCES 1;
    This script could be modified to reflect the features you want for your database.
    db01 = the name you can give to your database
    Good luck,
    Henri

  • What is an Instance in application server and how to create an Instance?

    Hi All,
    What is an Instance in application server and how to create an Instance? What is the procedure to get file path from an Instance?
    What is the significance of Instance in ABAP?

    hi
    good
    go through these links,this will gives you complee idea about the creating instances in application serverl.
    http://www.erpgenie.com/sap/basis/
    http://www.sapdevelopment.co.uk/file/file_disall.htm
    thanks
    mrutyun^

  • How to create xforms binding-excaption of xml file in the xhtml source?

    Hello,
    is anyone here who could help me?
    I've spent plenty of hours by searching the correct and suitable way for creating a binding exception in XForms, but I did not succeed...
    My situation is: I've got an XHTML page with XForms and XML (input) file, which describes this page. Whenewer I change the input data in the XML file (for example there are tags <person> and ....</person> if I change it to <peson1> and ...</person1>) after saving the changes and refreshing the page, the XForms will be changed (for example some text fields are missing or they've got white background instead red one, which there was before et cetera). {I hope it is clear till now.....}
    My task is: to create a xforms-binding-expression event, which will display an error message (for example: FILE HAVE BEEN CHANGED, CAN NOT DISPLAY THE PAGE PROPERLY) to the user.
    i've found some stuff, how to create such message, but i need to know the exact order of commands to make it work, where to insert them, the structure etc, so I can comprehend your advices...
    The XHTML file contains of several blocks - bind, model, submission, instance etc - and I do not actually know, where to insert such lines (with message)...I think I should make some bindings with the page loading, but I've got no idea how to get it done, however there are very few sites with such stuff on the internet. I hope this task is no big deal for you gyus, THANK YOU A LOT IN ADVANCE

    Hello,
    is anyone here who could help me?
    I've spent plenty of hours by searching the correct and suitable way for creating a binding exception in XForms, but I did not succeed...
    My situation is: I've got an XHTML page with XForms and XML (input) file, which describes this page. Whenewer I change the input data in the XML file (for example there are tags <person> and ....</person> if I change it to <peson1> and ...</person1>) after saving the changes and refreshing the page, the XForms will be changed (for example some text fields are missing or they've got white background instead red one, which there was before et cetera). {I hope it is clear till now.....}
    My task is: to create a xforms-binding-expression event, which will display an error message (for example: FILE HAVE BEEN CHANGED, CAN NOT DISPLAY THE PAGE PROPERLY) to the user.
    i've found some stuff, how to create such message, but i need to know the exact order of commands to make it work, where to insert them, the structure etc, so I can comprehend your advices...
    The XHTML file contains of several blocks - bind, model, submission, instance etc - and I do not actually know, where to insert such lines (with message)...I think I should make some bindings with the page loading, but I've got no idea how to get it done, however there are very few sites with such stuff on the internet. I hope this task is no big deal for you gyus, THANK YOU A LOT IN ADVANCE

  • How to create  a procedure to send a mail if the Database is down?

    Hi,
    I have created the below procedure to send a mail if the count is less than 1300. It scheduled daily @ 15 30 hrs. Its fine.
    CREATE OR REPLACE procedure SCOTT.hrsmail
    is
    v_count number;
    begin
    Select count(*) into v_count from emp;
    if v_count < 1300
    then
    UTL_MAIL.send(sender => '[email protected]',
    recipients => '[email protected]',
    cc => '[email protected]',
    bcc => '[email protected]',
    subject => 'Testing the UTL_MAIL Package',
    message => 'If you get this, UTL_MAIL package
    else
    null; --what you want to do here
    end if ;
    end;
    Sometime the Database is down, so the job is not running.
    How to create a procedure to send a mail if the database is down?
    Pls help me. Its highly appreciated.
    Thanks
    Nihar

    nihar wrote:
    How to create a procedure to send a mail if the database is down?And what if the database is up, but the network down? Or the database up and mail server down? Or mail server undergoing maintenance?
    There are loads of "+What if's+" - and in that respect, playing "+What if database is down..+" in this case does not make any sense. You do not use the database to monitor its own up/down status. You do not rely just on SMTP as notification protocol that the database is down.
    The correct approach would be using something like SNMP as the monitoring protocol. A monitoring system that can process SNMP and perform some basic root cause analysis (e.g. network to the database server down, database server status unknown). And this system supporting notification methods like SMTP, SMS and so on.

  • How to create a new tag in page properties in the sidekick of geometrrix page

    how to create a new tag in page properties in the sidekick of geometrrix pagesame as basic, advanced, blue print??

    Hi prachi,
        Is it tag OR Tab ? Seems like you are looking for Tab. Look at [1] & overlay to custamize per your need. Or define at your page component.
        [1]   /libs/foundation/components/page/dialog/items/tabs/items
    Thanks,
    Sham

  • How to create a pop up window while creation of the delivery note.

    Hello Experts
    How to create a pop up window while creation of the delivery note.
    As soon as we go in to delivery note creation screen in VL01N, immediately a pop up screen should be displayed on the screen containing the following details,
    For e.g.
    Str. Loc     Qty      UOM
    DE01        100        KG
    DE99          50        KG

    Dear all,
    i m having two document numbers for invoic of same types such as output type print program and smartform.
    biut the issue is im getting print preview for one invoic and for another invoic i m not getting any print preview.
    Directly the cursor comes to initial stage of vf03.
    suggest what to do
    Thanks and regarnds
    ravi

  • How to create a exe file of a .class file

    how to create a .exe file for windows .class file of java
    please answer this so that i can complete the project to be submited to collage

    There is a program called JET. Is enables you to create .exe files of .class files.
    This is the URL:
    http://www.excelsior-usa.com/jet.html
    Succes
    --=tReShR=--

  • HT2731 how to create a free apple id without puttin in the cridit card info?

    how to create a free apple id without puttin in the cridit card info?
    Card type "None" option is not available

    Welcome to the Apple Community.
    To be able to download free apps without a recognised method of payment or gift card.
    Open iTunes and navigate to the app store. Select a free app to download. A simple way to do this is to scroll down to the top free apps box on the right hand side, hover your mouse over the first item and click on the free button that appears when you hover over it.
    A pop up will open asking you to sign in with your Apple ID click "create new account", click continue to create your account. Check the box to accept the store terms and conditions and click continue.
    Enter your email address, password, security question, and date of birth, click continue. Now, you will be asked to provide a payment method. Note now that the last option says "none".

  • How to create an object of our own class by using Class.forName()??

    how to create an object of our own class by using Class.forName()??
    plzz anser my qustion soon..

    Class.forName does not create an object. It returns a reference to the Class object that describes the metadata for the class in question--what methods and fields it has, etc.
    To create an object--regardless of whether it's your class or some other class--you could call newInstance on the Class object returned from Class.forName, BUT only if that class has a no-arg constructor that you want to call.
    Class<MyClass> clazz = Class.forName("com.mycompany.MyClass");
    MyClass mine = clazz.newInstance();If you want to use a constructor that takes parameters, you'll have to use java.lang.reflect.Constructor.
    Google for java reflection tutorial for more details.
    BUT reflection is often abused, and often employe when not needed. Why is it that you think you need this?

  • How to create an rule with action to subtract from the event log of Ips manager express console?

    how to create an rule with action to subtract from the event log of Ips manager express console?, some knows of has an guide?.
    Thank you.
    Sent from Cisco Technical Support iPad App

    Hi,
    http://www.cisco.com/en/US/products/sw/secursw/ps2113/products_tech_note09186a0080bc7910.shtml
    HTH
    Luis Silva
    "If you need PDI (Planning, Design, Implement) assistance feel free to reach us"
    http://www.cisco.com/web/partners/tools/pdihd.html

Maybe you are looking for