Private static MyInnerClass extends OtherClass + protected methods

Hi!
Consider this case:
public class A {
private static class A1 extends B {
// this would resolve the error:
//       protected static void b() { B.b(); }
void a() { A1.b(); } // ERROR: B.b() is inaccessible
public class B {
protected static void b() {}
}(Where A and B are in different packages.)
Why is B.b() inaccessible here?
A1 extends B, so it sees its protected methods.
A is a nesting class of A1, so it sees the protected methods of A1.
What am I missing here?
Thank you!
Agoston

OK, my mistake, I missed the part about different
packages.
However the following further inner class of A
compiles for me:
     private static class A2 extends A1
          A2()
               b();
               A1.b();
     }using the OP's original code without A1.b().That's what I was talking about: b() can be called from children, but not from the nesting class.
>
The statement quoted from the JCP exam is not
correct. The inherited protected member is available
to subclasses of A1, so the protected member
b() doesn't 'become private' at all. It stays as is
was, i.e. protected, i.e. accessible within the
original package or to subclasses.If it stays protected, why can't the nesting class see it? (Once again, a protected method defined in A1 and not inherited from B is visible from A.)
It seems as if the inherited protected method teleports into some mysterious realm of visibility levels between private and protected. (I.e. it's like protected, only from a nesting class it's seen as super-private - since the nesting class should even be able to see the private methods of its inner class, shouldn't it?)
This whole inconsequent behavior on the part of the compiler feels like a huge bug to me.
Nothing changes.Unfortunately. :)
Agoston

Similar Messages

  • Forcing invocation of private/protected methods

    Has anyone, any idea how can be forced the invocation of a private/protected method on a object. The client that invokes the method has a reference to the object and is declared in a different object than the targeted object.
    See code below:
    package src.client;
    import java.lang.reflect.Method;
    import src.provider.CPBook;
    public class Tester {
         public static void main(String [] args) {
              CPBook targetObj = new CPBook();
              Method [] mths = targetObj.getClass().getDeclaredMethods();
              Method targetMth = null;
              for (int i = 0; i < mths.length; i++) {               
                   if ("getMgr".equals(mths.getName())) {
                        targetMth = mths[i];
              if (targetMth != null) {
                   try {
                        Object [] obj = new Object[1];
                        obj[0] = new Boolean(true);
                        targetMth.invoke(b, obj);
                   } catch (Exception e) {                    
                        e.printStackTrace();
    package src.provider;
    public class CPBook {
         public void startDownload() {                    
         public void stopDownload() {     
         protected void getMgr(boolean bool) {
              System.out.println("------- OK ------- : " + bool);
    }Thank you.
    Best regards.

    The class java.lang.reflect.Method has a setAccessible(boolean) method on it. I think that's what you're asking for. Code that makes use of it might run into trouble if a security manager is involved, though. Generally, methods are private for a reason, too, so if your code depends on a private method, it's dependent on an implementation detail it probably shouldn't be concerned about, or even aware of

  • Applying Private & Protected methods inside JSP

    I am trying to apply (or copy) codings from Servlet into JSP.
    One of the issue that I encountered was bringing Private and Protected methods that were listed inside the Servlet class (this case: public abstract class CatalogPage).
    If I only copy everything inside "Public void doGet", JSP would not work.
    1) My question is, is it better approach to apply Private and Protected method beside wrapping around with ( <%! %> (with !)) (like below)?
    I think I heard about using " ! " for private methods somewhere in the internet..
    Here is what I have at JSP.
    <%!
    Private CatalogItem[] items;
    Private String[] itemIDs;
    private String title;
    protected void setItems(String[] itemIDs) {
    protected void setTitle(String title) {
    %>
    <%
    if (items == null) {
    response.sendError(response.SC_NOT_FOUND,
    "Missing Items.");
    return;
    %>
    2) Is there any other ways I could make the functionality of Private and Protected methods
    work inside the JSP's <% %>?
    Thank you.
    Here is the original Servlet code.
    public abstract class CatalogPage extends HttpServlet {
      private CatalogItem[] items;
      private String[] itemIDs;
      private String title;
      protected void setItems(String[] itemIDs) {
        this.itemIDs = itemIDs;
        items = new CatalogItem[itemIDs.length];
        for(int i=0; i<items.length; i++) {
          items[i] = Catalog.getItem(itemIDs);
    protected void setTitle(String title) {
    this.title = title;
    public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {
    if (items == null) {
    response.sendError(response.SC_NOT_FOUND,
    "Missing Items.");
    return;
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String docType =
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
    "Transitional//EN\">\n";
    out.println(docType +
    "<HTML>\n" +
    "<HEAD><TITLE>" + title + "</TITLE></HEAD>\n" +
    "<BODY BGCOLOR=\"#FDF5E6\">\n" +
    "<H1 ALIGN=\"CENTER\">" + title + "</H1>");
    CatalogItem item;
    for(int i=0; i<items.length; i++) {
    out.println("<HR>");
    item = items[i];
    // Show error message if subclass lists item ID
    // that's not in the catalog.
    if (item == null) {
    out.println("<FONT COLOR=\"RED\">" +
    "Unknown item ID " + itemIDs[i] +
    "</FONT>");
    } else {
    out.println();
    String formURL =
    "/servlet/coreservlets.OrderPage";
    // Pass URLs that reference own site through encodeURL.
    formURL = response.encodeURL(formURL);
    out.println
    ("<FORM ACTION=\"" + formURL + "\">\n" +
    "<INPUT TYPE=\"HIDDEN\" NAME=\"itemID\" " +
    " VALUE=\"" + item.getItemID() + "\">\n" +
    "<H2>" + item.getShortDescription() +
    " ($" + item.getCost() + ")</H2>\n" +
    item.getLongDescription() + "\n" +
    "<P>\n<CENTER>\n" +
    "<INPUT TYPE=\"SUBMIT\" " +
    "VALUE=\"Add to Shopping Cart\">\n" +
    "</CENTER>\n<P>\n</FORM>");
    out.println("<HR>\n</BODY></HTML>");
    null

    I am trying to apply (or copy) codings from Servlet into JSP.What benefit is there to copying code from a servlet to a JSP? Is the servlet "working"?
    One of the issue that I encountered was bringing
    Private and Protected methods that were listed inside
    the Servlet class.
    If I just copy everything inside "Public void doGet",
    JSP would not work.Sounds like you need a redesign.
    1) My question is, is it better approach to apply
    Private and Protected method beside wrapping around
    with ( <%! %> (with !)) (like below)?
    I think I heard about using " ! " for private
    methods somewhere in the internet..Never heard of such a thing. Please cite the link if you have it.
    Here is what I have at JSP.Please, I can't look. This is wrong on so many levels. You've got scriptlet code, CSS style stuff, embedded HTML in one unmaintainable mess.
    Learn JSTL and CSS. Do not, under any circumstances, put scriptlet code in your JSP.
    The right way is to use the JSP purely as display and keep those protected and private methods on the server side where they belong. Have the JSP make a request to another object to do some work, get the result, and displa it.
    %

  • Why do we need private static method or member class

    Dear java gurus,
    I have a question about the use of private and static key words together in a method or inner class.
    If we want to hide the method, private is enough. a private static method is sure not intended to be called outside the class. So the only usage I could see is that this private static method is to be called by another static method. For inner class, I see the definition of Entry inner class in java.util.Hashtable, it is static private. I don't know why not just define it as private. Could the static key word do anything better.
    Could anybody help me to clear this.
    Thanks,

    What don't you get? Private does one thing, andstatic does >something completely different.
    If you want to listen to music, installing an airconditioner doesn't help>
    Hi, if the private keyword is the airconditioner, do
    you think you could get music from the static keyword
    (it acts as the CD player) in the following codes:You're making no sense and you're trying to stretch the analogy too far.
    Private does one thing. If you want that thing, use private.
    Static does something completely different and unrelated. If you want that thing, use static.
    If you want both things, use private static.
    What do you not understand? How can you claim that you understand that they are different, and then ask, "Why do we need static if we have private"? That question makes no sense if you actually do understand that they're different.

  • What is the use of private static method/variable?

    Hi All,
    I have read lots of books and tried lots of things but still not very clear on the
    topic above.
    When exactly do we HAVE to use private static methods?
    private implies its only for class, cannot be accessed outside.
    But then static means, it can be accessed giving classname.method.
    They seem to be contradicting each other.
    Any examples explaining the exact behaviour will be well appreciated.
    Thanks,
    Chandra Mohan

    Static doesn't really "mean" that the method/field is intended for use outside the class - that is exactly what the access modifier is for.
    Static implies that it is for use in relation to the class itself, as opposed to an instance of the class.
    One good example of a private static method would be a utility method that is (only) invoked by other (possibly public) static methods; it is not required outside the class (indeed, it might be dangerous to expose the method) but it must be called from another static method so it, in turn, must be static.
    Hope this helps.

  • Private static method

    How do I get access to a private static method of a class?
    I can't just call it by object.privatemethod() , right?

    unless your call is made within the body of the
    class, you cannot call it, otherwise just call it via
    a static ref of the class
    ObjectName.privateMethod()
    (not)
    ObjectInstance.privateMethod()...where "ObjectName" is the name of the class.
    Or you can just call it with privateMethod(), but that tends so suggest "this.privateMethod()" so I'd go with qualifying it with the class name, to be clear.

  • Innerclass access of extended protected methods

    I have a subclass X() which extends class Y() and has an anonymous innerclass. The innerclass extends classs z() and accesses a protected method of the extended class y(). This works fine in jdk1.3, but causes a java.lang.NoSuchMethodError in jdk1.4...
    Any ideas on why it works in jdk1.3 but not in jdk1.4?
    Thanks,
    Bruce

    Sorry, you were correct... I was going between jdk1.4
    and jdk1.3 and messed up. Let me restate the problem:
    I have a class CreateVLANGroup() which extends class ProvisionPanel().
    Class CreateVLANGroup() creates an instance of WaitMessageHandler(). WaitMessageHandler() has a method setExecutionCommand() which takes as an argument "ExecutionCommandInterface object". CreateVLANGroup() uses an anonymous innerclass to create this argument for the call to setExecutionCommandInterface(). It is the call "CreateVLANGroup.this.displayModelData()" from within the innerclass that causes the jdk1.4 error.
    See the snippet of code from CreateVLANGroup() below.
         public CreateVLANGroup(PF3000View view, DMXEthernetCircuitPack model)
              super(view, model);
              ... initialization code here
    WaitMessageHandler handler = new WaitMessageHandler(this,
    "Retrieving data for this Ethernet Circuit Pack, please wait...");
    handler.setExecutionCommand(new ExecutionCommandInterface()
    public void execute(Object target) {
    if (systemProperties.isTrue("ExpandedEthernetSupported")) {
    virtualIDs = m_dmxPortCircuitPack.getVRTSWFabric().getAllVRTSWIds().toArray();
    if (getVirtualSwitches() != null &&
    getVirtualSwitches().length != 0)
    CreateVLANGroup.this.displayModelData();
    else
    return;
    } else {
    displayModelData();
    handler.execute(new Object());
    The actual error that I'm getting at runtime is:
    java.lang.NoSuchMethodError: com.lucent.cit.gui.sysview.core.common.ProvisionPanel.access$301(Lcom/lucent/cit/gui/sysview/product/dialogs/provision/CreateVLANGroup;)V
    at com.lucent.cit.gui.sysview.product.dialogs.provision.CreateVLANGroup$1.execute(CreateVLANGroup.java:58)
    at com.lucent.cit.gui.util.waiting.WaitMessageHandler$WaitMessageHandlerThread.run(WaitMessageHandler.java:595)

  • Private static method accessed from main, please explain

    hi,
    i dont understand what happened with this code:
    static means you dont have to have an object to call the method - fine.
    but private means that the method is only available within the class,
    so how can one call the method initLookAndFeel() from main?
    public class Converter{
       //constructors etc...
       private static void initlookAndFee(){/* do stuff */}
    }//end of class converter
    public static void main( String args[]){
       initLookAndFeel(); ///????????????????????????????????????
       Converter converter = new Converter();
    }//end of main

    ...dang those stupid SMALL parenthesis!
    yes, main IS within the class converter... doh!
    thanx. M.

  • Not sure how to use protected method in arraylisy

    Hi,
    Im wondering how to use the removeRange method in java arraylist, its a protected method which returns void.
    http://java.sun.com/j2se/1.3/docs/api/java/util/ArrayList.html#removeRange(int,%20int)
    So if my class extends Arraylist i should be able to call the method but the compiler states that it still has protected access in arraylist. Does this mean im still overriding the method in arraylist ? A little explanation of whats happeneing would be appreciated as much as an answer
    thanks

    In this codefinal class myClass extends java.util.ArrayList {
        private ArrayList array = new ArrayList();
        public myClass(ArrayList ary){
            for(int i=0;i<7;i++) {
                array.add(ary.get(i));
            ary.removeRange(0,7)
    }You are defining a class called myClass which extends ArrayList.
    You have a member variable called array which is an ArrayList
    You have a constructor which takes a parameter called ary which is an ArrayList
    Since ary is an ArrayList, you cannot call it's removeRange() method unless myClass is in the java.util package. Do not put your class in the java.util package.
    It seems like what you want to do is to move the items in one ArrayList to another ArrayList rather than copying them. I wrote a program to do this. Here it isimport java.util.*;
    public class Test3 {
      public static void main(String[] args) {
        MyClass myClass = new MyClass();
        for (int i=0; i<5; i++) myClass.add("Item-"+i);
        System.out.println("------ myClass loaded -------");
        for (int i=0; i<myClass.size(); i++) System.out.println(myClass.get(i));
        MyClass newClass = new MyClass(myClass);
        System.out.println("------ newClass created -------");
        for (int i=0; i<newClass.size(); i++) System.out.println(newClass.get(i));
        System.out.println("------ myClass now contains -------");
        for (int i=0; i<myClass.size(); i++) System.out.println(myClass.get(i));
    class MyClass extends java.util.ArrayList {
        public MyClass() {}
        public MyClass(MyClass ary){
            for(int i=0;i<ary.size();i++) add(ary.get(i));
            ary.removeRange(0,ary.size());
    }You should notice now that I don't create an ArrayList anywhere. Everything is a MyClass. By the way, class names are normally capitalized, variable names are not. Hence this line
    MyClass myClass = new MyClass();
    In the code above I create an empty MyClass and then populate it with 5 items and then print that list. Then I create a new MyClass using the constructor which takes a MyClass parameter. This copies the items from the parameter list into the newly created MyClass (which is an ArrayList) and then removes the items from the MyClass passed as a parameter. Back in the main() method, I then print the contents of the two MyClass objects.
    One thing which may be a little confusing is this line.
    for(int i=0;i<ary.size();i++) add(ary.get(i));
    the add() call doesn't refer to anything. What it really refers to is the newly created MyClass object which this constructor is building. This newly created object is the 'this' object. So the line above could be rewritten as
    for(int i=0;i<ary.size();i++) this.add(ary.get(i));
    Hopefully this helps a little. The problems you seem to be having are associated with object oriented concepts. You might try reading this
    http://sepwww.stanford.edu/sep/josman/oop/oop1.htm

  • Private static SearchTree empty = empty();

    hi
    i have a problem understanding why modifying a particular line of code from its original form to another form does not compile.
    Original Statement:
    private static SearchTree empty = empty();
    The way I Modified it to:
    private static SearchTree empty;
    empty = empty();
    I get compilation errrors but the program executes. I have explained the same at the end of the code listing.
    class NodeTree extends SearchTree {
        private Comparable data;  // the data item at the root
        private SearchTree left;  // the left subtree
        private SearchTree right; // the right subtree
        //private = accessible to members only within the package
        <b>private static SearchTree empty = empty(); </b>
         * This class ought not to be instantiated directly
         //this constructor is used to instantiate a new NodeTree Object
         //which contains a left 'SearchTree', a right 'SearchTree'
         //and a data item
        protected NodeTree(Comparable item) {
            data = item;
            left = empty;
            right = empty;
        public boolean isEmpty() {
            return false;
        public int nrNodes() {
            return left.nrNodes() + right.nrNodes() + 1;
        public boolean contains(Comparable item) {
            int compare = item.compareTo(data);
            if (compare < 0) {
                return left.contains(item);
            } else if (compare > 0) {
                return right.contains(item);
            } else {
                return true;
        //t = t.add(new Integer(item)); // 40
        public SearchTree add(Comparable item)
             //the compareTo() method returns an integer
             //depending on the result of comparison
             //Here the comparison is being carried out
             //between 'this' which is nothing but 'item'
             //and 'data'
            int compare = item.compareTo(data);
            //compareTo returns and integer that is 0 if the
            // object is less than 'this', 1 if both are equal
            //and a positive integer if greater
            if (compare < 0) {
                left = left.add(item);
            } else if (compare > 0) {
                right = right.add(item);
            return this;
            //here the 'this' refers to the NodeTree obejc
        /* private method for use in public method <remove>
         * returns smallest item in non-empty tree
        private Comparable findMin() {
            if (left.isEmpty()) {
                return data;
            } else {
                return ((NodeTree) left).findMin();
        /* private method for use in public method <remove> 
         * removes node containing smallest item in non-empty tree
        private SearchTree removeMin() {
            if (left.isEmpty()) {
                return right;
            } else {
                left = ((NodeTree) left).removeMin();
                return this;
        public SearchTree remove(Comparable item) {
            int compare = item.compareTo(data);
            if (compare == 0 && right.isEmpty()) {
                return left;
            } else {
                if (compare < 0) {
                    left = left.remove(item);
                } else if (compare > 0) {
                    right = right.remove(item);
                } else { // compare == 0 and !right.isEmpty()
                    data = ((NodeTree) right).findMin();
                    right = ((NodeTree) right).removeMin();
                return this;
        public Enumeration elementsLevelOrder() {
            return new Enumeration() {
                private Queue q = new QueueArray();
                { // initialise the queue
                    q.enqueue(NodeTree.this);
                public boolean hasMoreElements() {
                    return !q.isEmpty();
                public Object nextElement() {
                    NodeTree root = (NodeTree) q.dequeue();
                    if (!root.left.isEmpty()) {
                        q.enqueue(root.left);
                    if (!root.right.isEmpty()) {
                        q.enqueue(root.right);
                    return root.data;
        // a class of objects to stack for in-order traversals
        // would also serve for PreOrder and PostOrder if required
        private class StackItem {
            NodeTree root; // the subtree we are currently processing
            boolean ready; // whether we are ready to return its root data
            StackItem(NodeTree root, boolean ready) {
                this.root = root;
                this.ready = ready;
        public Enumeration elementsInOrder() {
            return new Enumeration() {
                private Stack s = new StackArray();
                { // initialise the stack      
                    s.push(new StackItem(NodeTree.this, false));
                public boolean hasMoreElements() {
                    return !s.isEmpty();
                public Object nextElement() {
                    StackItem next = (StackItem) s.pop();
                    while (!next.ready) {
                        NodeTree root = next.root;
                        if (!root.right.isEmpty()) {
                            s.push(new StackItem((NodeTree) root.right, false));
                        // relocate the next line to get PreOrder or PostOrder
                        s.push(new StackItem(root, true));
                        if (!root.left.isEmpty()) {
                            s.push(new StackItem((NodeTree) root.left, false));
                        next = (StackItem) s.pop();
                    return next.root.data;
        public String toString() {
            String string = "";
            if (!left.isEmpty() && !right.isEmpty()) {
                string += "(" + left + " " + data + " " + right + ")";
            } else if (!left.isEmpty()) {
                string += "(" + left + " " + data + " .)";
            } else if (!right.isEmpty()) {
                string += "(. " + data + " " + right + ")";
            } else {
                string += data;
            return string;
    I tried to rewrite the following line ( the one that is made bold) in a different way as below:
    Original Statement:
    private static SearchTree empty = empty();
    Modified:
    private static SearchTree empty;
    empty = empty();
    and this does not work:
    the following errors were given by the compiler:
    D:\Documents and Settings\ilango\Desktop\javanotes\SearchTreeDemo.java:236: <identifier> expected
    empty = empty();
    ^
    D:\Documents and Settings\ilango\Desktop\javanotes\SearchTreeDemo.java:236: cannot resolve symbol
    symbol : class empty
    location: class DataStructures.NodeTree
    empty = empty();
    ^
    2 errors
    Process completed.
    But suprisingly the program runs perfectly. I get the desired output.
    I may be naive on this, but could somebody explain what's going on.
    thanks in advance

    You cannot write static code like this in your class,
    since the compiler has no idea that this is static code or variable-initialisation.
    Try the following:
    private static SearchTree empty;
        empty = empty();
    }This introduces a block of static code to be run at the loading and initialisation of the class.
    You could add more lines of code in this static-block.
    kind regards,

  • Protected methods in abstract classes

    Hello All
    I have some problem which I cannot find a workaround for.
    I have three classes:
    package my.one;
    public abstract class First {
      protected void do();
      protected void now();
    package my.one;
    public class NotWantToHave extends First {
      protected First obj;
      public NotWantToHave(First O) { obj = O; }
      public void do() { obj.do(); }
      public void now() { obj.now(); }
    package my.two;
    public class Second extends my.one.First {
      protected void do() { System.out.println("Second does"); }
      protected void now() { System.out.println("Second does now"); }
    package my.three;
    public class Three extends my.one.First {
      protected my.one.First obj;
      public Three(my.one.First O) { obj = O; }
      protected void do() { System.out.println("Doing"); }
      protected void now() { obj.now(); } // Not possible, see later text
    Problem is, as one can read in http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html , it says that you cannot access protected members and methods from classes if they are in a different package. However, since my class Three should not concern about the method now() but should use from some other class that implements (i.e. class Second), the question I have is how to do?
    One way would be to implement a class that simply make a forward call to any protected method in the same package the abstract class is in like in class NotWantToHave and pass it to the constructor of class Third while this class was created with an instance of class Second. However, such a call would look very clumsy (new my.three.Third(new my.one.NotWantToHave(new my.two.Second()));). Furthermore, everyone could create an instance of class NotWantToHave and can invoke the methods defined as protected in class First, so the access restriction would be quite useless.
    Does anyone has a good idea how to do?

    Hi
    One way I found is to have a nested, protected static final class in my super-class First and provide a protected static final method that returns a class where all methods of the super-class are made public and thus accessible from sub-classes at will. The only requirement is that a sub-class must invoke this method to encapsulate other implementations of the super-class and never publish the wrapper class instance. This will look as follows:
    package my.one;
    public abstract class First {
      protected final static class Wrap extends First { // extend First to make sure not to forget any abstract method
        protected First F;
        public void do() { F.do(); }
        public void now() { F.now(); }
        protected Wrap(First Obj) { F = Obj; }
      } // end Wrap
      protected final static First.Wrap wrap(First Obj) { return new First.Wrap(Obj); }
      protected abstract void do();
      protected abstract void now();
    } // end First*******
    package my.two;
    public class Second extends my.one.First {
      protected void do() { System.out.println("Second does"); }
      protected void now() { System.out.println("Second does now"); }
    } // end Second*******
    package my.three;
    public class Three extends my.one.First {
      protected my.one.First.Wrap obj;
      public Three(my.one.First O) { obj = my.one.First.wrap(O); }
      protected void do() { System.out.println("Doing"); }
      protected void now() { obj.now(); } // Not possible, see later text
    } // end Third*******
    In this way, I can access all methods in the abstract super class since the Wrap class makes them public while the methods are not accessible from outside the package to i.e. a GUI that uses the protocol.
    However, it still looks clumsy and I would appreciate very much if someone knows a more clear solution.
    And, please, do not tell me that I stand on my rope and wonder why I fall down. I hope I know what I am doing and of course, I know the specification (why else I should mention about the link to the specification and refer to it?). But I am quite sure that I am not the first person facing this problem and I hope someone out there could tell me about their solution.
    My requirements are to access protected methods on sub-classes of a super-class that are not known yet (because they are developed in the far, far future ...) in other sub-classes of the same super-class without make those methods public to not inveigle their usage where they should not be used.
    Thanks

  • Problems on protected methods

    Hi!
    Im rhani, im new to java programming....i was trying to run this code from a book (below) :
    import java.awt.*;
    public class FrameExample extends Frame {
    public static void main(String args[]){
    FrameExample win = new FrameExample();
    public FrameExample() {
    super("FrameExample");
    pack();
    resize(400,400);
    show();
    public void paint(Graphics g) {
    g.drawString("A Basic Window Program",100,100);
    public boolean handleEvent(Event event) {
    if(event.id==Event.WINDOW_DESTROY){
    System.exit(0);
    return true;
    }else return false;
    (Im using jdk1.3.1_12)
    ahmm now it says that the method handleEvent is deprecated. Now then I tried to replaced it with :
    protected void processEvent (AWTEvent e) {
    if (e.getID == Event.WINDOW_DESTROY) {
    System.exit(0);
    no errors but i know my "if " condition is wrong....when i try to use e.id == WINDOW_DESTROY it says that im trying to access a protected method on that. Im just having difficulty in what really does a protected method does..or its limitations....and how would I be able to handle that the user is trying to close the frame/window. I would really do appreciate your help on this....I hope I had explained it clearly, ahm im not good in english...ahmm thank you very much!!!

    thank you very much sir for the fast reply...ahm i dont know if Im using the right method...ahmm its just that the documentation here http://java.sun.com/j2se/1.3/docs/api/ says that it inherits a method from Class Component, then it says that I should use processEvent, ahm the processEvent there is declared protected void processEvent ( AWTEvent e). Then on e.getID() ahm it says that it returns an int value I just thought that its value is like WINDOW_DESTROY or something...thank you very much again sir for the help...

  • Protected methods

    I've been programming in Java for about three years, and once I believed I had understood something, but now...
    I have a base class, like this:
    public abstract class Base
      protected abstract void method();
    }I've also a derived class, like this:
    public class Derived extends Base
      protected void method()
        System.out.println("yep!");
    }And, finally, the Main class:
    public class Main
      public static void main(String[] args)
        Base b = new Derived();
        b.method();
    }Now I'd expect the compiler complaining that method() of class Base is protected, hence not accessible from class Main. Instead the compiler happily builds the bytecode, the bytecode happily runs and the program happily outputs "yep!". What am I missing?

    I will assume that your classes are in
    the default package.In fact they are.
    >
    protected methods are available to all classes in
    the same package, and to all subclasses.So what is the difference between protected methods and "package access" ones, which are the ones without access modifier declaration such as
    public abstract class Base
      abstract void method();

  • Private static ArrayList within java.util.Arrays

    I was recently reviewing the code in java.util.Arrays (class version 1.45 - Java version 1.4.1). Beginning on line 2289 is a private static class named ArrayList. I'm completely baffled as to why the author created this slimmed-down private class (which would be, incidentally, returned by the Arrays.asList(Object[] a) method) rather than use the public class java.util.ArrayList. Can anyone offer an explanation?
    Thanks,
    John

    from JDK JAVADoc:
    asList
    public static List asList(Object[] a)
    Returns a fixed-size list backed by the specified array. (Changes to the returned list "write through" to the array.) This method acts as bridge between array-based and collection-based APIs, in combination with Collection.toArray. The returned list is serializable.
    So the private ArrayList extends java.util.ArrayList, and any changes made this list does not affect the internal Object[].... in other words can not be changed.

  • How to use protected method in jsp code

    Could anyone tell me how to use protected method in jsp code ...
    I declare a Calendar class , and I want to use the isTimeSet method ,
    But if I write the code as follows ..
    ========================================================
    <%
    Calendar create_date = Calendar.getInstance();
    if (create_date.isTimeSet) System.out.println("true");
    %>
    ============================================================
    when I run this jsp , it appears the error wirtten "isTimeSet has protected access in java.util.Calendar"

    The only way to access a protected variable is to subclass.
    MyCalendar extends Calendar
    but I doubt you need to do this. If you only want to tell if a Calendar object has a time associated with it, try using
    cal.isSet( Calendar.HOUR );

Maybe you are looking for

  • Adobe Bridge CS6 undefined in not an object Help Please

    I am so sick and tired of getting this error message when I try to create a pdf contact sheet - undefined is not an object.  Can someone help me? What frustrates me the is there is no log file telling me what image has the problem which Bridge does n

  • ITunes wont download because of Quicktime?

    When I try to download itunes it wont let me because it says the quicktime is needed. ive tried and tried and i got to the point were i actually downloaded quicktime seperatley and it still does not work. ive checked the forums up and down and i cant

  • Invalid char in XML from inbound IDoc

    I am trying to send a CREMDM IDoc from a 4.6C R/3 system to an XI SP09 system. The IDoc gets sent from the backend system, shows up fine in WE05, but after it gets passed to XI, I encounter a fatal error (in SXMB_MONI) that reads: com.sap.aii.utilxi.

  • Has my hard drive failed, and if so can I replace it myself?

    Can someone help me, please? I believe my hard drive has failed (or is about to) and needs replacing. Problem is I took my laptop (Powerbook G4, 15" 1.5GHz 512MB 80G Sdrv APX, recently upgraded to OS10.5) to our local official Apple Store to be servi

  • Images in themes no longer have transparent background after upgrade?

    I've just upgraded to iLife 09 and also Snow Leopard. Unfortunately when I open iDVD the 7.0 themes won't load properly. There is no dropzone in the Revolution theme and the Sunflower theme moving images no longer have transparent background so have