Protected class

hi ppl,
          Iam new to this oops concept..i learnt that to access the contents of a protected class either we have call by subclass and another is with in itself.so how can we call a protected class with in class itself..pls do alter this code to call within itself
class snap definition.
protected section.
methods: m1.
data: d type char20 value 'PROTECTED'.
endclass.
class snap implementation.
method: m1.
write:/ d.
endmethod.
endclass.
start-of-selection.
data obj type ref to snap.
create object obj.
call method->m1.
end-of-selection.

Hi Priyank,
Marcin's correct but there was a small typo in his post:
  me->me1( ).
Is supposed to be:
me->m1( ).
as m1 is the name of the protected method. In case you're wondering, "me" is a self reference to the instance. It is not necessary, e.g. you could write just
m1( ).
but including the self reference is considered good practice because it increases the understandability of the code.
Best regards, Erik

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 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

  • Error: No public or protected classes found to document.

    Hello,
    I am currently going spare trying to get javadoc to document the code I have written. I have checked the Java code given the information on the website and the comments are correct and complete for all methods. The command line I am using is:
    c:\j2sdk1.4.1_01\bin\javadoc.exe -d docs/ Population.javaAnd the makefile (bat file) is in the directory with the population.java file. The command line works with other files in the same directory, programmed and commented to the same standard. The error I get is:
    C:\Documents and Settings\ril\MYDOCU~1\PROGRA~1\JCreator\ILCSFrame>c:\j2sdk1.4.1_01\bin\javadoc.exe -d docs/ Population.java
    Loading source file ILCSFrame.java...
    Constructing Javadoc information...
    Standard Doclet version 1.4.1
    Generating docs/\constant-values.html...
    javadoc: No public or protected classes found to document.
    1 errorI have tried checking the documentation with the doccheck doclet with the following command line:
    c:\j2sdk1.4.1_01\bin\javadoc.exe -doclet com.sun.tools.doclets.doccheck.DocCheck -docletpath C:\j2sdk1.4.1_01\utils\doccheck1.2b1\lib Population.javaBut it throws the following error:
    C:\Documents and Settings\ril\MYDOCU~1\PROGRA~1\JCreator\ILCSFrame>c:\j2sdk1.4.1
    _01\bin\javadoc.exe -doclet com.sun.tools.doclets.doccheck.DocCheck -docletpath
    C:\j2sdk1.4.1_01\utils\doccheck1.2b1\lib\doccheck.jar Population.java
    Loading source file Population.java...
    Constructing Javadoc information...
    javadoc: In doclet class com.sun.tools.doclets.doccheck.DocCheck,  method start
    has thrown an exception java.lang.reflect.InvocationTargetException
    java.lang.NoSuchMethodError: com.sun.tools.doclets.HtmlWriter.<init>(Ljava/lang/
    String;Ljava/lang/String;)V
            at com.sun.tools.doclets.doccheck.HtmlWriterExt.<init>(HtmlWriterExt.jav
    a:16)
            at com.sun.tools.doclets.doccheck.DocCheck.makeWriter(DocCheck.java:1407
            at com.sun.tools.doclets.doccheck.DocCheck.printStatisticsPage(DocCheck.
    java:456)
            at com.sun.tools.doclets.doccheck.DocCheck.printErrorPages(DocCheck.java
    :433)
            at com.sun.tools.doclets.doccheck.DocCheck.startGeneration(DocCheck.java
    :364)
            at com.sun.tools.doclets.doccheck.DocCheck.start(DocCheck.java:337)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
    java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
    sorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:324)
            at com.sun.tools.javadoc.DocletInvoker.invoke(DocletInvoker.java:193)
            at com.sun.tools.javadoc.DocletInvoker.start(DocletInvoker.java:92)
            at com.sun.tools.javadoc.Start.parseAndExecute(Start.java:301)
            at com.sun.tools.javadoc.Start.begin(Start.java:120)
            at com.sun.tools.javadoc.Main.execute(Main.java:41)
            at com.sun.tools.javadoc.Main.main(Main.java:31)
    1 errorIf I try running doccheck (without doclet) on the whole directory (containing 6 java files), it will only pick up 3 of them (one including the SwingWorker java file). Any help greatly appreciated.

    "No public or protected classes found to document" means
    that the class Population.java is not in the current directory.
    Without trying to insult your programming ability, these things
    come to mind:
    - Omit the slash at the end of "-d docs/" This causes the
    message "Generating docs/\constant-values.html.
    I'm not sure why the bat file uses a forward slash on
    a Windows system.
    - Make sure you cd to the directory containing the bat file before
    running it.
    - Java is case-sensitive (I notice you spelled the filename
    both uppercase and lowercase.) Make sure the file name,
    the class name in the class, and the class name in the bat
    file have the same case.
    As far as doccheck not running, we have not yet released the
    version that runs on 1.4.x. Please write to "doccheck-feedback"
    with "@sun.com" for more info. (I've broken up the email address
    so text crawlers won't get it.)
    -Doug Kramer
    Javadoc team

  • Accessing inner protected class with .new

    My weak understanding is that inner classes are no different in terms of access modification as other class members, thus I was expecting the following to compile:
    package A;
    public class ClassA {
        protected void protectedMethod() {}
        protected class ProtectedInnerClass {}
    }is being used over here in package B
    package B;
    import A.*;
    public class ClassB extends ClassA {
    public static void main(String[] args) {
    ClassB b = new ClassB();
    b.protectedMethod(); // works fine. I am inheriting ClassA and calling the protected method.
    ClassB.ProtectedInnerClass c = b.new ProtectedInnerClass(); // compiler error: ProtectedInnerClass is protected
    }Why can I not access the protected inner class when ClassB is inheriting it as is the case with the protected method?
    thanks in advance!

    So classes that inherit other classes with protected inner classes will not be able to instantiate these inner classes regardless of the inheritance relationship.No, that's not true. Example:
    package A;
    public class ClassA {
         protected void protectedMethod() {
         protected class ProtectedInnerClass { // class is protected
              public ProtectedInnerClass() { } // <-- nota bene
    package B;
    import A.ClassA;
    public class ClassB extends ClassA {
         public static void main(String[] args) {
              ClassB b = new ClassB();
              b.protectedMethod(); // works fine.
              ClassB.ProtectedInnerClass c = b.new ProtectedInnerClass(); // works fine, too.
    }It's section 6.6.2.2 that describes this behavior, as I quoted above. The last bullet point of that section reads (to repeat): "A protected constructor can be accessed by a class instance creation expression (that does not declare an anonymous class) only from within the package in which it is defined."
    ~

  • How to protect protected classes?

    I�m Brazilian, and I am learning English language yet. I�ll try to describe my problem.
    I am using protected and friendly classes, but it doesn�t avoid anyone to use them, because if someone knows the package name of my protected class, this person can create a class with the same name of the package, and my protected and friendly classes are now unprotected! Anyone can instantiate my classes in this way.
    Did anyone go through this situation? Is there solution for it?
    Thank you so much!

    There is a solution. I created the same post in Programming section of this forum, that is more apropriate, and there a user called Shag-VT posted a solution.
    The way to ensure that nobody is getting into your classes is to "seal" the >package in the manifest and then sign the jar with a digital signature.
    The followng like contains a discussion of how to add a digital signature to the >jar (it's just the general documentation for a jar file):
    http://java.sun.com/j2se/1.4.2/docs/guide/jar/jar.html
    It also has a link to another file, which shows how to seal the package. For >convenience, here is the link:
    http://java.sun.com/j2se/1.4.2/docs/guide/extensions/spec.html#sealing

  • Protected class give an error ?

    when i write protected class, just for learning purpose it gives me an error why ?
    here is code
    protected class A
    void display()
    System.out.println("A");
    it gives an error ? why ? can u justify ?
    why default and public is allowed and why not private and protected ?
    pragnesh

    In Java, the top level class should always be public; or there should not be any modifiers.
    There is no point in making a top-level class protected as it is not visible to the outside world.
    However, you can make inner classes protected.

  • EJBs accessing protected classes from java classloader

    Hello,
    We are facing a problem with classes isolation. I read from this newsgroup that
    to access a package level class from the base classloader from a bean, the supporting
    classes has to be from the same classloader as the bean. Well I think the only
    way we could do that is to have the *Bean.class in the base classloader, which
    is not what's recommended or move the support classes into the bean's classloader,
    which we cannot do.
    The purpose of this mail is to ask: is it a bug from weblogic server? Will it
    be fixed one day? If not, does it mean that it is impossible to isolate classes
    for local access from public classes?
    Thank you, Khiet.

    Thank you for your reply.
    Hope that one day we will not be obliged to have anything in the main classpath.
    :) Khiet.
    Rob Woollen <[email protected]> wrote:
    Tran T. Khiet wrote:
    Hello,
    We are facing a problem with classes isolation. I read from this newsgroupthat
    to access a package level class from the base classloader from a bean,the supporting
    classes has to be from the same classloader as the bean. Well I thinkthe only
    way we could do that is to have the *Bean.class in the base classloader,which
    is not what's recommended or move the support classes into the bean'sclassloader,
    which we cannot do.All correct.
    The purpose of this mail is to ask: is it a bug from weblogic server?No, it's how java classloaders work.
    Will it
    be fixed one day? If not, does it mean that it is impossible to isolateclasses
    for local access from public classes?You can expect that future versions of WLS will allow the user more
    control over classloaders, but for now you'll need public or protected
    access to cross classloaders.
    -- Rob
    Thank you, Khiet.

  • Protect class Files from Decryption?

    Hey. I have a couple of Java classes I wish to share with some people, but I would like to add a copyright/credit giving message into the program. This code is the kind of code people would want to steal and take credit for, which is why I'm only (if I can encrypt them) giving out the .class files and not the source code. The thing is, it took me about 5 seconds of searching on Google to find programs that can easily be used to decrypt .class files and get a re-compilable source from them.
    So I was wondering, is there a [somewhat] foolproof way to protect against people decrypting the .class files to get the source? Is there some program I can run them through that will make it so they can't be decompiled, but will still run on a machine with a standard Java runtime installed? I probably won't be giving out the classes if there isn't a way to do this.
    Thanks

    There are programs out their that semi pseudo scramble your code but if someone wanted to they can always reverse it and have a look at your source. What you have to admit is that your code is nothing special and nobody would really want to steal your code. If you are paranoid about it, about the most you can do is add some copyright message and threaten them with legal action.

  • What is the best way to protect .class files on server?

    I've been working on my website project for quite some time, years in fact. Now I'm at the point where I'm looking into signing up with a web host provider and testing the site live.
    I have some questions and concerns though. My site is made up of Java Servlets and JSP pages.
    My foremost concern is protecting my code. Many suggest obfuscating. If I understand the process correctly, it involves making the code harder to decompile. I also understand that obfuscating isn't a guarantee in protecting code. If someone really wants to use the code, they'll figure out a way to.
    So are there any other options available to protect my code?? I would like to consider as many options as possible.
    Once it is on the web host server, anyone can have access to it. Hope this doesn't sound like a stupid question - Microsoft Word comes with the option to password protect files from being opened, is there not by now some way to implement the same sort of feature with files uploaded to a server?
    Your input is appreciated.

    ejp wrote:
    Once it is on the web host server, anyone can have access to it.That's not true. You're off on the wrong track before you even start. You need to acquire a proper understanding of a web server and its configuration. Your problem can be solved via correct configuration of the server. Nothing to do with obfuscation.So your telling me that once I've uploaded all my .class files and everything else to my host provider, that the people running the server do not have access to it? I find this hard to believe....
    What exactly would I be looking to configure on the server??? Please explain.

  • Trying to call method in in protected class

    I thought I had this code right, but when this line executes, I dump with
    You attempted to use a 'NULL' object reference (points to 'nothing').
    I'm trying to call  a method that exists in a nother class. 
    In view ServHeader.  I've created ZL_CRM_IC_SERVHEADER_IMP2 with a superclass
    CL_CRM_IC_SERVHEADER_IMP2.  In DO_PREPARE_OUTPUT I'm trying to call a method that exist in IRecReason.  I can't cll it directly because TYPED_CONTEXT is protected, so I created  ZCL_CRM_IC_IRECREASON_IMPL with superclass CL_CRM_IC_IRECREASON_IMPL.  Created a new attributed ZTYPED_CONTEXT and made it public and a type ref to CL_CRM_IC_IRECREASON_CTXT.
    In DO_PREPARE_OUTPUT I have this code.
    Data:  z_irecreason type REF TO ZCL_CRM_IC_IRECREASON_IMPL.
    create object z_irecreason.
    Z_IRECREASON->ztyped_context->statush->on_new_focus( current ).
    What am I missing?   Thanks, Cathy

    You have to create a Instance of ztyped_context similar to code in CL_CRM_IC_IRECREASON->WD_CREATE_CONTEXT

  • Obfuscation of protected class members - good/bad?

    Hi,
    there was a post regarding de-obfuscation, so i thought I�d ask a philosophical question and your opinion on another related problem.
    I�ve seen an API for one product with protected methods and viriables documented in the javadoc. However, when trying to subclass API classes, it turns out that these protected methods have been obfuscated, often making meaningful subclassing impossible.
    What do people think about such things? How do such practices stand from the OOP point of view? I would guess this is a bad violation...
    Philip

    After all, I don't understand the point of
    obfuscation. The JVM was designed in a way that
    de-obfuscators are always on the strong side -- The
    JVM has to ensure even for obfuscated programs that
    they don't do any damage to your system, so it must
    (kind of) de-obfuscate them.An example of obfuscation:
    before:
    if (KeyValidator.validate(userKey, userName)) { 
      runApplication();
    } else {
      displayMessage("Your key is invalid, please purchace a key...");
      System.exit(0);
    }If you dowloaded a demo, decompiled it and looked at the code it would be easy to hack it to make it work without a key... so the creators of the code obfuscate it. This renames methods and objects, replaces strings with encryped strings transformed my a method, and throws in meaningless code:
    after:
    if (a(A.a).b(c, C){
      x();
    } else if (z.c(e.rr(0x03<<2) {
    } else{
      z(xlp("[2039rj[0q4q[q03q4hr[q09f[0f9h[0qwe9hf[q0we9r8[0q23f[02934");
      System.exit(0);
    }now that this garbage is in the middle of 1.5M of similar source code, it's no longer obvious what this does.
    Similarly, obfuscated code can protect proprietary algorithms.

  • Constructor of package protected class

    Why has class Test no constructor when trying to get the default constructor by reflection.
    class Test {
         public static void main(String[] args){
              try {
                   Class test=Test.class;
                   Constructor[] ctor= test.getConstructors();
                   System.out.println(ctor.length);
              } catch (Exception e) {
                   e.printStackTrace();
    }

    Returns:
    the array of Class objects representing all the
    the declared members of this classWrong citation:
    Returns an array containing Constructor objects reflecting all the public constructors of the class represented by this Class object. An array of length 0 is returned if the class has no public constructors, or if the class is an array class, or if the class reflects a primitive type or void.

  • How to protect class files from being decompiled?

    any ideas
    guide me

    You may consider looking into Java native compilers.
    I'm referring to compilers that take existing Java
    code and convert them into native executables rather
    than class files which are interpreted.yeah... kills portability too.

  • Why a base class cannot be a Private or Protected ?????

    why a base class cannot be a Private or Protected ?????

    why a base class cannot be a Private orProtected
    ?????Who would be able to access it? (Assuming "base"
    means top-level class.)Private, none. Protected, all classes in same package
    and subclasses (as with the methods).
    Actually, its somewhat illogical that a class be
    declared package-private, but not protected, since
    protected is less restrictive.having a protected class would make no sense. subclasses are not permitted to lessen the protection of members of their superclass, so you'd end up with a class that nothing could use, except subclasses that in turn nothing else could use

Maybe you are looking for

  • GR/IR Account

    hi gurus, I have situation where the GR/IR account was created without open item managed.and now they want to make it open item , But account has line items /Values , it been in use for almost a year. now that they are reconciling it end of fiscal ye

  • Microsoft wireless mouse?

    Hello, I'm trying to set up a new mac mini. Can I use a Microsoft wireless keyboard and mouse with it? It appears to recognize the keyboard and mouse, but once i get to the country-selection page, I cannot pick an entry from the table though I can na

  • Custom F4 in ALV List

    Hi, I am working on REUSE_ALV_LIST_DISPLAY FM. I want to have a Custom F4 Editable field in the ALV. I am able to get a standard F4 help, that is by making use of ref_fieldname and ref_tabname  in the field catalog. I need help in achieving Custom F4

  • Help Urgent....MAYSCRIPT and netscape

    Hello i want to acces JSObject in my applet calss, for this purpose i have imported import netscape.javascript.JSException; import netscape.javascript.JSObject; in my class files And in the html file i have written following code <EMBED type="applica

  • What is MRP and why it is used?

    hi this question was asked in an interview can some one explain in detail for me What is MRP and why it is used? If there are 2 Lakhs of items is it feasiable to run MRP since running of MRP for 2 lakhs of item is time consuming, if yes then how it i