Why java is giving 'attempting to assign weaker access privileges'  error?

Can some one can tell me why java is giving 'attempting to assign weaker access privileges' compile error while compiling Abhishekchild.java ?
The two classes is :
public class  Abhishek {
       void asd()
     System.out.println("hello");
          static String a;
          public static void main (String st[])
public class  Abhishekchild extends Abhishek {
     private  void asd()
     System.out.println("hello");
          static String a;
          public static void main (String st[])
}In my opinion, java compiler is showing the error , as method asd has public visibility in Abhishek. java so
(i)it should be visble to all sub classes of Abhishek.java.
But if we override this function in Abhishekchild.java, and change the visibility to private then it will not be available for child of Abhishekchild.java. But these children are also children of Abhishek.java*, but this violates rule (i).*
So java shows a compilation error.

public class Parent {
     public void asd() {
          System.out.println("Hello");
class Child extends Parent {
     public void asd() {
          System.out.println("Hello from child");
     public static void main(String st[]) {
          Parent parentReference = new Child();
          // The reference 'parentReference' knows about Parent.
          // Parent has a public method asd, so below code looks ok.
          // But if child could set the method to private,
          // invoking the code below, would hit the object Child,
          // where asd() is not accessible - and everything fails.
          // Note - the compile visibility is checked according to
          // the reference, not the object itself.
          parentReference.asd();
}See my comments in the code.
- Roy

Similar Messages

  • Why Java doesn't allow to reduce the accessibility of a method du

    Why Java compiler does not allow to reduce the accessibility of a method during inheritance?
    ( Eg; If the base class has a public method and if that method is overridden in child class but
    with defuault access, it gives compile error)
    Supposed answer:
    Because in the runtime, it cannot check the access modifier.
    Suppose A is the base class. It has a method fun() as public.
    B is the derived class of A.
    Suppose in some other class (say C) there is a method myFun() which takes A as parameter and
    calls the fun() method of A. So that method can take B
    also as parameter (As it is derived from A).
    So if the fun() method's accessibility is reduced in B, whether "that can
    be called in C or not" is not known. that is why compiler does not
    allow the reduce the accessibility of a method during inheritance.
    Member variables do not have this problem as they can be checked at
    compile time.
    Is this explanation correct?

    You can give private access, sort of... you could fake it, if the goal is to prevent someone from doing what the method does. Of course, they could (as long as A isn't abstract) create their own A and do whatever they want.
    class A {
       public void doThis() {
    class B extends A {
       public void doThis() {
          // explicitly do nothing
    }But I think generally, this shouldn't be a problem. I'm not sure if it's something that is common for creating an API to subclass another class to hide the superclass's methods. Usually you are adding functionality to a subclass that is for more specific things then the superclass supports. I mention creating an API because if it's just for some application class, then you are writing it, so use or not use the methods as you want. It's APIs for library type classes that other people would use, and if you are extending the library, and really need people not to call methods for some reason, document it. Maybe a good place for an assertion?

  • Jaas sample progrma in weblogic 6.1 giving the following error java.lang.SecurityException: attempting to add an object which is not an instance of java.security.Principal to a Subjec

    jaas sample progrma in weblogic 6.1 giving the following error java.lang.SecurityException:
    attempting to add an object which is not an instance of java.security.Principal
    to a Subjec
    on runnig the program during the call of method Authenticate.authenticate(env,
    subject); giving following exceptions Error: Login Exception on authenticate,
    java.lang.SecurityException: attempting to add an object which is not an instance
    of java.security.Principal to a Subjec t's Principal Set Authentication Failed:
    Unexpected Exception, javax.security.auth.login.LoginExce ption: java.lang.SecurityException:
    attempting to add an object which is not an instance of java.security.Principal
    to a Subject's Principal Set javax.security.auth.login.LoginException: javax.security.auth.login.LoginExcepti
    on: java.lang.SecurityException: attempting to add an object which is not an ins
    tance of java.security.Principal to a Subject's Principal Set at examples.security.jaas.SampleLoginModule.login(SampleLoginModule.java
    :192) at java.lang.reflect.Method.invoke(Native Method) at javax.security.auth.login.LoginContext.invoke(LoginContext.java:595)
    at javax.security.auth.login.LoginContext.access$000(LoginContext.java:1 25) at
    javax.security.auth.login.LoginContext$3.run(LoginContext.java:531) at java.security.AccessController.doPrivileged(Native
    Method) at javax.security.auth.login.LoginContext.invokeModule(LoginContext.java
    :528) at javax.security.auth.login.LoginContext.login(LoginContext.java:449) at
    examples.security.jaas.SampleClient.main(SampleClient.java:96)
    1)what is the reason for this problem
    2)in weblogic document they told to edit server.policy file in webligic\lib folder
    a)what the modification is needed in this file..?

    Hi jerry
    i already got that problem solved by removing jaas.jar file
    from class path.
    i don'nt how it is working with out in classpath...?
    Jerry <[email protected]> wrote:
    Hi Nivas,
    I think that the problem you are seeing has something to do with the
    placement of jaas.jar in your classpath
    On WebLogic server, put jaas.jar in the classpath after weblogic.jar.
    I would bet that you have it placed before weblogic.jar right now.
    I don't think the exception that you're seeing right now has anything
    to do with your weblogic.policy file right now, so I think it is
    safe to not worry about it right now.
    Hope this helps,
    Joe Jerry

  • Why java is free?

    I don't understand why java technology is free to download, and even more of this, the source code is available.
    I think sun can make a lot of money from us. (without giving ideas)

    They're trying mic$ofts trick - for years micro$oft offered wondoze on easy to copy disks, with little or no security (even though they could have implemented some kind) knowing that people would pirate it, and spread it around very quickly. Then, when most of the computing world is hooked on using windoze, they upgrade to a flashy secure version that you have to pay loads for. It was a gamble, but certainly paid off. What sun are doing is the only possible tactic for them at the moment, which is to spread java as much as possible to ensure loads of people use it - they are not doing this for fun, or the love of the language, but purley and simply as a business strategy.

  • Why can't i install java on os 10.7, under install it says error  something about java script

    why can't i install java on os 10.7, under install it says error  something about java script

    If you can't get any software updates, there is something wrong and I would suggest reinstalling Lion.
    What errors do you get when you try to install the updates?
    What is the build number of Lion. Look in About this Mac and click on the version number.

  • Java.lang.Exception: Attempted to use a 5.0 DataSource outside of a 2.3 ser

    Receiving error message: java.lang.Exception: Attempted to use a 5.0 DataSource outside of a 2.3 Servlet
    The application worked fine with 2.2 servlet version and data source 4.0
    But i need to add some filter in web.xml so
    I changed the servlet version in my web.xml from
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> to
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
    and created a data source version 5 in websphere server 6.0.0.1
    After that it is throwing the above mentioned error. pls help me on this.
    Thanks

    Is there anything i need to change in my application.xml
    <!DOCTYPE application PUBLIC "-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN" "http://java.sun.com/j2ee/dtds/application_1_2.dtd">

  • Why java file name and class name are equal

    could u explain why java file name and class name are equal in java

    The relevant section of the JLS (?7.6):
    When packages are stored in a file system (?7.2.1), the host system may choose to enforce the restriction that it is a compile-time error if a type is not found in a file under a name composed of the type name plus an extension (such as .java or .jav) if either of the following is true:
    * The type is referred to by code in other compilation units of the package in which the type is declared.
    * The type is declared public (and therefore is potentially accessible from code in other packages).
    This restriction implies that there must be at most one such type per compilation unit. This restriction makes it easy for a compiler for the Java programming language or an implementation of the Java virtual machine to find a named class within a package; for example, the source code for a public type wet.sprocket.Toad would be found in a file Toad.java in the directory wet/sprocket, and the corresponding object code would be found in the file Toad.class in the same directory.
    When packages are stored in a database (?7.2.2), the host system must not impose such restrictions. In practice, many programmers choose to put each class or interface type in its own compilation unit, whether or not it is public or is referred to by code in other compilation units.

  • Why Java Web Start doesn't support Pack200 out-of-the-box?

    Hello All,
    Why Java Web Start doesn't support Pack200 out-of-the-box? I was hoping that Java 6 would make things easier by adding direct support for Pack200 in Java Web Start and JNLP without needing to use servlets, etc.? All my clients are Java 5 or above so I can't push the Pack200 compressed version of the jar to every single one of them and there is no selection process needed. But I can't do it because of the servlet or complex Apache server setup requirement (it would be a headache to get customers' web server admins to set up Apache or whatever web server that way).
    My question is why is there unwillingness to add Pack200 support directly to Java Web Start and JNLP so that you can start Pack200 compressed jars just like you would start any jar using Java Web Start? Is te a technical problem?
    Thank you,
    Mete Kural

    Hallo,
    I didn�t try it, but the webstart FAQ�s read:
    Can I use Pack200 compression with the JnlpDownloadServlet?
    Yes. The JnlpDownloadServlet distributed in the samples directory of the JDK now supports Pack200. If you deploy yourfile.jar along with yourfile.jar.pack.gz the packed file will be downloaded when the client is running Java Web Start 1.5.0 or later.
    http://java.sun.com/javase/6/docs/technotes/guides/javaws/developersguide/faq.html#217
    For further information you may want to look at
    http://java.sun.com/javase/6/docs/technotes/guides/javaws/developersguide/downloadservletguide.html#pack200
    The configuration of the server and the the servlet (as described in the second link) is as easy as it seems.
    I got it working on the first try and it was my first experience with websevers at all.
    Bye Schippe
    Message was edited by:
    Schippe

  • Why java is called java2

    why java is called java2 and another thing that i would like to know is why it was renamed to java from its previous name OAK
    Thanx
    Manish

    why java is called java2Not to sure about this one, but I think it was a marketing decision - I guess 'Welcome to the Java 2 platform' sounds better than saying 'Welcome to the JDK 1.2.1 platform' :=)
    and another thing that i
    would like to know is why it was renamed to java from
    its previous name OAKThere was already a patented product named 'OAK', so they had to rename it to something else to avoid the law.
    >
    Thanx
    ManishA brief history of Java:
    http://java.sun.com/features/1998/05/birthday.html
    http://www.ils.unc.edu/blaze/java/javahist.html

  • Why not nokia giving belle or other better update ...

    why not nokia giving belle or any other update for 5233, 5235, 5230
    Many of indians nokia phone user has disspointed after seeing android, and belle user interfence for other phones and not for nokia 5233,35,30 phones . Many of nokia users disspointed after that many of nokia users moving to android and other phons and not for nokia after that,
    Why not nokia giving any update hor these phones ..
    Solved!
    Go to Solution.

    The devices you mentioned are symbian S60V5. These cannot be upgraded to Nokia belle or such. They have hardware limitations.
    In Love With My C6-01:Now running on Nokia Belle!

  • Java.lang.IllegalStateException:Attempt to validate already invalid Region

    Hi,
    i am using jdev 11.1.1.2
    I am working in region, I drag drop the table and so on.Suddenly i start getting this error -”java.lang.IllegalStateException: Attempt to validate an already invalid RegionSite”.
    any idea how to solve it.

    check all these points..
    - Check all bindings of page. if you not able to find it then delete it and create again.
    - Add the “-Djbo.debugoutput=console” in JAVA options of the Run/Debug/Profile to see the error
    - Check if all the library references for the UI project are proper and that is also accessible.

  • Why java is platform independent ?

    what is the meaning of java is platform independent ? is it just because of java code can be run in windows/linux/unix platform ? but then C/C++ also can be run in windows/linux/unix . so why those are not called platform independent ?
    why java is called platform independent ?

    c/c++ creates object code . similary java creates bytecode . java uses interpreter JVM to execute . similary c/c++ object code also executes in any platform. so where is the real difference ?
    the classes do not need to be recompiled for different platforms. what do u mean by this ? ".....classes ( i.e bytecode) dont need recompilation ..." .....ok....but same thing is true for C/C++ object code also !! they also dont need recompilation.
    where is the difference ?

  • Blog post: Embedded Software: Disruptions Ahead - Why Java makes sense

    All,
    You may be interested in this blog post I did two days ago, which talks about the challenges in embedded software design and why Java makes sense for embedded software engineering:
    https://terrencebarr.wordpress.com/2013/08/05/embedded-software-disruptions-ahead/
    Best,
    Terrence

    (bump)

  • Java.lang.IllegalStateException: Attempt to modify the CacheName

    Hi,
    I received an error today that I had never seen before -
    2007-12-05 17:04:43.006 Oracle Coherence GE 3.3/387 <Error> (thread=ReplicatedCache, member=1): Terminating ReplicatedCache due to unhandled exception: java.lang.IllegalStateException
    2007-12-05 17:04:43.007 Oracle Coherence GE 3.3/387 <Error> (thread=ReplicatedCache, member=1):
    java.lang.IllegalStateException: Attempt to modify the CacheName: CacheHandler{Name=PRICES-2007-11-20-EMEA-IR&#44;IRS, Index=114, ServiceName=ReplicatedCache, ClassLoader=weblogic.utils.classloaders.ChangeAwareClassLoader@384621f finder: weblogic.utils.classloaders.CodeGenClassFinder@3846290 annotation: monitor-service@monitor-service} to WORKFLOW-TASK-2007-11-20-EMEA
         at com.tangosol.coherence.component.util.CacheHandler.setCacheName(CacheHandler.CDB:10)
         at com.tangosol.coherence.component.util.CacheHandler.fromXml(CacheHandler.CDB:3)
         at com.tangosol.coherence.component.util.daemon.queueProcessor.service.ReplicatedCache.onCatalogUpdate(ReplicatedCache.CDB:14)
         at com.tangosol.coherence.component.util.cacheHandler.CatalogHandler.entryInserted(CatalogHandler.CDB:6)
         at com.tangosol.util.MapEvent.dispatch(MapEvent.java:191)
         at com.tangosol.util.MapEvent.dispatch(MapEvent.java:164)
         at com.tangosol.util.MapListenerSupport.fireEvent(MapListenerSupport.java:556)
         at com.tangosol.coherence.component.util.CacheHandler.onLeaseUpdate(CacheHandler.CDB:83)
         at com.tangosol.coherence.component.util.daemon.queueProcessor.service.ReplicatedCache$LeaseUpdate.onReceived(ReplicatedCache.CDB:10)
         at com.tangosol.coherence.component.util.daemon.queueProcessor.Service.onMessage(Service.CDB:9)
         at com.tangosol.coherence.component.util.daemon.queueProcessor.Service.onNotify(Service.CDB:21)
         at com.tangosol.coherence.component.util.daemon.queueProcessor.service.ReplicatedCache.onNotify(ReplicatedCache.CDB:3)
         at com.tangosol.coherence.component.util.Daemon.run(Daemon.CDB:35)
         at java.lang.Thread.run()V(Unknown Source)
    This caused the ReplicatedCache to restart.
    Note that the "PRICES-2007-11-20-EMEA-IR&#44;IRS" cache and the "WORKFLOW-TASK-2007-11-20-EMEA" cache would have been created around about the same time.
    Does anyone have any suggestions as to what happend?
    Thanks,
    Dermot

    Hello,
    I believe this support issue is currently being addressed via an Oracle service request through Metalink.
    Thanks,
    Patrick

  • Solution to: javax.naming.AuthenticationException.  Root exception is java.lang.SecurityException: attempting to add an object which is not an instance of java.security.Principal to a Subject's Principal Set

    Hello world,
    To anybody who receives this irritating error in a Java client
    application attempting to access Weblogic Server 6.1 (and possibly
    weblogic server 6):
    javax.naming.AuthenticationException. Root exception is
    java.lang.SecurityException: attempting to add an object which is not
    an instance of java.security.Principal to a Subject's Principal Set
    The cause of your problem is having JAAS explicitly in your classpath.
    It somehow messes up authentication to WebLogic. Remove it and your
    problem will disappear.
    The complete exception was:
    javax.naming.AuthenticationException. Root exception is
    java.lang.SecurityException: attempting to add an object which is not
    an instance of java.security.Principal to a Subject's Principal Set
         at javax.security.auth.Subject$SecureSet.add(Subject.java:1098)
         at weblogic.common.internal.BootServicesStub.writeUserInfoToSubject(BootServicesStub.java:72)
         at weblogic.common.internal.BootServicesStub.authenticate(BootServicesStub.java:80)
         at weblogic.security.acl.internal.Security.authenticate(Security.java:108)
         at weblogic.jndi.WLInitialContextFactoryDelegate.pushUser(WLInitialContextFactoryDelegate.java:509)
         at weblogic.jndi.WLInitialContextFactoryDelegate.newContext(WLInitialContextFactoryDelegate.java:364)
         at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:336)
         at weblogic.jndi.WLInitialContextFactoryDelegate.getInitialContext(WLInitialContextFactoryDelegate.java:208)
         at weblogic.jndi.WLInitialContextFactory.getInitialContext(WLInitialContextFactory.java:149)
         at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:668)
         at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:246)
         at javax.naming.InitialContext.init(InitialContext.java:222)
         at javax.naming.InitialContext.<init>(InitialContext.java:198)
         at au.com.orrcon.orrconcentral.Application.<init>(Application.java:87)
         at au.com.orrcon.orrconcentral.Application.getApp(Application.java:52)
         at au.com.orrcon.orrconcentral.orrconCentral.<init>(orrconCentral.java:130)
         at au.com.orrcon.orrconcentral.orrconCentral.main(orrconCentral.java:219)

    Steve Wesemeyer <[email protected]> wrote:
    I have encountered the same problem and I do not have JAAS on my classpath
    at all (unless it's there by default). Are there any other possible
    causes for this?
    Cheers,
    SteveA note to all who read this thread:
    I also had to remove Sun's j2ee (version 1.2) from my client's classpath before
    the same problem went away. 1 programmer day down the drain....
    Regards,
    MG

Maybe you are looking for

  • How to hide purchase in iTunes 12?

    It appears none of the previous methods in iTunes 12 work. I need to hide a useless 1gb app which keeps wanting to download. Any information gratefully received.

  • Show records corresponding to last date of last 3 months

    Experts, I have a list of records in my logical table like this. All I need to do is create an analysis that will show the records corresponding to last date of the last 3 months. Assuming current month is July. The report must show only the highligh

  • IPod touch home button single tap = double tap

    Sometimes when I tap the home button on my iPod touch 4th gen (iOS 5.1.1), it acts as if I double-tapped. I have already replaced it under warranty. Is this a common issue? Should I ask apple for another swap or will it not make a difference?

  • Probleme avec photoshop element 9

    Bonjour j'ai un soucis avec Photoshop element 9, il ne veut plus s ouvrir. Il m ecrit un message: We're sorry, but the safari browser version you are currently using does not support the community tollbar. Je suis sur mac et je n'ai rien toucher au s

  • I cant locate capture devices!!!! Please HELP!!!

    I am trying to send voice over to another computer but right now I cant get my program to detect my capture device. I looked through the forum for solutions and found 2 solutions- 1 is using the JMF registry editor and click on "connect capture devic