Access Modifier private

Hi
1.
EX Code in java:
private class SS{  }
There is any way i can save a file as SS.java and i need to compile this without error like - private might not allowed
2. How to replace a String value?
Ex String x="abc";
Is there any way to replace this string without using any other string methods plz tell the answer.

vijay_raga wrote:
private class SS{  }
There is any way i can save a file as SS.java and i need to compile this without error like - private might not allowed
// private
class SS {}Satisfied ? BTW ,private modifier cannot be applied to class.But I guess this would not answer your question !!!
>
2. How to replace a String value?
Ex String x="abc";
Is there any way to replace this string without using any other string methods plz tell the answer.Replace with what ?
And what revolution do you wish to make by doing these things ?
Thanks.

Similar Messages

  • Private, protected Access Modifiers with a class

    Why cant we use private and protected access modifiers with a class?
    Thanks.

    Matiz wrote:
    >
    Public access allows you to extend a parent class in some other package. If you only want users to extend your class rather than instantiate it directly, make the class abstract and design for extension.Agreed. However, would the same argument be not true for the default access at the class level? No. Default access would only allow you to extend a parent class in the same package (as opposed to some other package).
    Now my confusion is why is a class allowed default access at the top level and not protected?Because protected for a top-level class makes no sense. The protected keyword provides member access to any other class in the same package and extending classes outside the package. A top-level class isn't a member of a class, by definition, so there's nothing that protected would do provide differently than public.
    So, the two access modifiers for a top-level class are public and default. Public allows access to the class outside the package, whereas default restricts access to the class within the package.
    ~

  • Default/package/none access modifier

    Hi,
    I was hoping for some discussion on the default/package/none access modifier. It's always really bugged me that we have public, private, protected, and then "none", while it seems to me that it would be less confusing, and more consistent to use the keyword "package", or maybe even "default".
    Then, source code would look like
    public class MyClass{
        public int getValue() {}
        private void setValue() {}
        protected void someMethod() {}
        package int justForPackage() {}
    }I know this concept has come up before, but the books I've read which mention this topic haven't offered any actaul justification/explanation for why there isn't some keyword.
    Anyway, are there any insights as to why java is this way, and any reasons why java should or shouldn't be changed to include the package access modifier.

    A good example is within a tightly grouped package (usually should be this way) you may have some cooperative classes that access methods.
    // one .java file
    public class SomeHelper {
       private void method() {
         new ClassForUsers().accessHiddenLogic();
    // next .java file in same package
    public ClassForUsers {
        /* default-access */ void accessHiddenLogic() {
    }But, you may want to allow users to subclass your ClassForUsers, without giving them access to the hidden logic method directly:
    // another .java file in a different package
    public class UsersSubclass extends ClassForUsers {
        public void userMethod() {
            // can't do this
            accessHiddenLogic();
    }This could be for either business logic or security reasons. So, package level access can be very useful. However, I've seen that in practice it is avoided because it isn't obvious what is going on.

  • Java class access modifiers

    Why java class cannot have private and protected access modifiers?

    class X {
      private class y {}
    }should compile just fine. A top-level private class makes no sense because you wouldn't be able to see it. As for protected, I don't know.

  • Inheritance and access control - "private protected"

    I'm reopening an old topic, seems to have been last discussed here 2-3 years ago.
    It concerns the concept of restricting access to class members to itself, and its subclasses. This is what "protected" does in C++ and "private protected" did in early versions of the Java language. This feature was removed from Java with a motivation along the lines of not being "simple", and "linear" (in line with the other access modes, each being a true subset of the next). Unfortunately, the article which explained Sun's position on this keyword combination seems to have been removed from the site, so I haven't been able to read its original text.
    But regardless of simplicity of implementation or explaining Java's access modifiers to newbies, I believe it is a fundamental part of OO programming for such an access mode to exist. The arguments for having the standard "private" mode in fact also apply for having a C++-style "protected" mode. (Arguing that classes within a package are related and it therefore doesn't hurt to also give them access to Java's "protected" members, is equally arguing that "private" is unneccessary, which noone of course believes.)
    The whole concept of inheritance and polymorphism and encapsulation builds on the access modes private, protected, and public (in the C++ senses). In Java the "package" concept was added - a nice feature! But I see no justification for it to negate the proper encapsulation of a class and its specializations.

    What effect upon inheritance other than hiding members
    from subclasses is there?
    None. And I cant think of another declaration that prevents members from being inherited but private.
    Of course the onus comes on the programmer with Java's
    definition of "protected" - but
    1) there is rarely a single programmer working within
    a package
    The point was the package is a unit which does not hide from itself. Just like all methods within a class can see each other, all classes within a package can, and all packages within a program can.
    2) it muddies the encapsulation in the design - when
    you see a "protected" method someone else, or yourself
    some time ago - wrote, how do you know if the design
    intention is to have it accessed solely by the class
    and its subclasses, or if it is indeed intended to be
    shared with the whole package? The only way to do
    this today is to always explicitly specify this in the
    comments, which may be lacking, inconsistent, and
    abused (since it isn't enforced).Encapsulation would be implementation hiding. Not method hiding. The only thing you should probably allow out of your package is an interface and a factory anyway.
    I understand where you are coming from, but I really have not had occasion to take issue with it. I can't think of a real codeing situation where this is required. OTOH, I can't think of a coding situation where I need to access a protected method from another class either.

  • Access modifier for Constructors ???

    As constructors are not the so called Members of a class
    (Class's Member declarations include only 4 things : variables , methods, member classes and member interfaces)
    Why do we have access modifiers for constructors also ??
    I know that if a class A 's constructor is declared 'private' , then that class cannot be instantiated outside the class A. .That is, class A can be instantiated only inside class A and provide this newly created reference to the outside world through public getter method.
    I dont understand how the other access modifiers (protected and default ) apply to a constructor.
    Any help from ur side is greatly appreciated !!!!!

    Why do we have access modifiers for constructors also
    ??To prevent anyone from accessing them if they shouldn't.
    I know that if a class A 's constructor is declared
    'private' , then that class cannot be instantiated
    outside the class A. Or you use another c'tor. Or a static getInstance() method provided by A. You you simply shouldn't create an instance yourself anyway.
    That is, class A can be
    instantiated only inside class A and provide this
    newly created reference to the outside world through
    public getter method.Yepp.
    I dont understand how the other access modifiers
    (protected and default ) apply to a constructor. Same as at other places. No difference.

  • Use of public access modifier in main method

    I want to know what is the significance of public access modifier with main (String args[]) method. Like generally we write
    public static void main(String args[])
    But if we write
    private static void main(String args[])
    OR
    protected static void main(String args[])
    then also its working properly.............
    then what is the use of public keyword..........................
    Regards
    Ajay Pratap Singh

    then what is the use of public keyword..........................Convention, I believe. And I think newer versions of the JVM require it.
    P.S. Relax a bit on the punctuation overuse. Many folks around here find that a bit irritating, and you probably don't intend to send that kind of a message. Cheers!

  • Usage of default access modifier

    Some programmers don't use the default access modifier (package level). Is there a specific reason? If so, what is it? Or is it a good to use default access modifier?
    Thank you,
    Srikanth

    Some prefer to grant or limit access to an object by the interface they expose. In this case all methods are either public or private. Access is restricted based on the fact that only the appropriate code is given references of certain interface types and if code does not have the right interface, they can not access the method.
    Its a different style, but I use it myself quite a bit. This way I never am concerned over if it should be public,private, protected or default. The choice is simpler. But sometimes it can make you create interfaces for really simple things which I am not uptight enough to do...

  • Access Modifier: Only Subclass, not package wide?

    Hello fellow programmers
    I'm looking for an access modifier that allows access to a method or member only from a class and it's subclasses. So it must be weaker than private because subclasses have access and stronger than protected because I don't want it to be accessible package wide.
    Is there such a modifier in Java?
    Regards
    Der Hinterwaeldler

    There used to be in a very early version of the language but it was dropped for clarity. IIRC it was called "private protected." Now you have to settle for "protected."
    This makes kind of sense since you have more control over the classes in your own package than over the subclasses that are not necessarily written by you ... If you can't trust other classes in the same package maybe you should put the class in a new package...

  • Access Modifiers Effect on Static Method Hiding Question

    I am studying for my SCJP exam and have come across a question that I do not understand and have not yet found a satisfactory explanation.
    Given:
    package staticExtend;
    public class A{
         private String runNow(){
              return "High";
         static class B extends A{
              public String runNow(){
                   return "Low";
         public static void main(String args[]){
              A[] a=new B[]{new B(),new C()};
              for(A aa:a)
                   System.out.print(aa.runNow()+" ");
    class C extends A.B{
         public String runNow(){
              return "Out";
    }The output is "High High". The explanation in the sample exam from ExamLab was that because the runNow() method in A was private that only an explicit cast to the B class would invoke the runNow() method in B. I have verified that that is the case, but am not clear on how the runNow() method being declared static in B and how the private access modifier in A results in this behaviour.
    Any additional explanation would be greatly appreciated.
    Thanks in advance.
    -- Ryan

    Ryan_Chapin wrote:
    OK, so since runNow() in A is private the compiler determines that regardless of the available methods in any of it's sub classes that since we declared the original array reference as "A" that it will invoke the runNow() in A. It's also due to the fact that the invocation came from within A. You would have gotten a compile time error if you tried to place the code in the main method in another class.
    >
    My mistake about the second part that you mention. You are correct. runNow() in B is NOT static, but the class is static. I guess that was the red herring in this question I don't see how that is related. I actually think that the "red herring" was what I described above. The fact that the code was placed in A, and that private methods can't be overridden.
    and the fact that the class itself is static has nothing to do with the behaviour that is being illustrated. Is that correct?Correct

  • Access modifiers

    I dint understood the below question properly, please help me out.......
    You want subclasses in any package to have access to members of a superclass. Which is
    the most restrictive access that accomplishes this objective?
    A. public
    B. private
    C. protected
    D. transient
    E. default access
    I want to know whether the question is relating to class access modifiers or methods and variables of the classes...

    I didnt get you, please explain the topic properly.... I think classes can have only public and default as an access modifier, is it rite??? That's right. Look at [this,|http://java.sun.com/docs/books/tutorial/java/javaOO/accesscontrol.html] it will give you a better understanding of the topic than you'd get from me answering your question.

  • Old access modifiers persisting after recompile

    Hello,
    I was following the Sun Tutorials for beginners and got to the exercise about developing Card and Deck classes (http://java.sun.com/docs/books/tutorial/java/javaOO/QandE/creating-answers.html). To see if I understood the concepts about access modifiers I tried tinkering with the supplied answers, Card.java and DisplayDeck.java.
    I did the following:
    1) In Card.java, changed the class constant, DIAMONDS to private.
    2) Recompiled Card.java.
    3) Ran DisplayDeck, which uses Card.DIAMONDS.
    I did not get a run-time error. I don't understand why. Doesn't DisplayDeck.class use the latest Card.class file? Apparently not. I tried restarting my DOS session and running again. Still no error. Does DisplayDeck.class somehow keep its own version of the Card class until you recompile DisplayDeck?
    4) Then I recompiled DisplayDeck and got a compile error. This I understand.
    Thanks.
    John

    Ontological wrote:
    Thanks. Is the Bytecode the .class file? Are you saying that when you compile class B, which uses class A, that all constants from class A are stored in the Bytecode for class B?One way to work around this is to use a static initializer. This way the values are not determined at compile time, so they can't be put into dependent classes. I don't really care for this though. I'd just rather recompile everything.
    public class Constants {
      public static final int X;
      public static final int Y;
      static {
        X = 123;
        Y = 456;
    }

  • What is the difference between access specifiers and access modifiers?

    what is the difference between access specifiers and access modifiers? are they same? if not what is the difference.

    Access Specifier are used to specifiy how the member variable ,methods or class to other classes.They are public ,private and protected.
    Access Modifier:
    1.Access
    2.Non Access
    Access:
    public ,private,protected and default.
    Non Access:
    abstract,final,native,static,synchronized,transient,volatile and strictfp

  • Static main(String args[]) access modifiers possible

    main(String args[]) can have private as access modifier?

    hi,
    yes of course this is possible, because main is at the end only a method like each other. But you have to know, that you cannot use this method from outside. so no application will start, if the main() of the Main-class has a private as modifier.
    You can use this class as an applet.
    So be carefull doing this
    regards

  • Security.Cryptography - The specified path is invalid. while accessing the private key stored in LocalMachine store

    Hello,
    I have C# dll which is invoked through a C++ cgi executable which is deployed on apache 2.2. I am getting the following error when I am trying to access the private key of a certificate which is stored in the Localmachine store. It works fine while
    debugging in visual studio.
    It also works fine when I try to access the same certificate from the current user store through apache.
    I have tried running apache as "SYSTEM", even then I get the same error.
    I have followed the right process to import the certificate into the localmachine store through mmc. 
    Error Message:
    The specified path is invalid.
     caused by mscorlib
       at System.Security.Cryptography.Utils.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer)
       at System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType, CspParameters parameters, Boolean randomKeyContainer, Int32 dwKeySize, SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle)
       at System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair()
       at System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize, CspParameters parameters, Boolean useDefaultKeySize)
       at System.Security.Cryptography.X509Certificates.X509Certificate2.get_PrivateKey()
       at SamlImplLib.SamlImpl.GetSamlResponse(String sInParamXml, String sInAttrXml)
    The above error is not really helpful as it doesnt tell me which path is invalid as I am not passing any path in my code. I am just accessing the certificate through the X509Certificate2 store
    Thanks in advance

    Hi,
    This is probably because the worker process identity does not have read permission to the machine key store.
    And I agree with you. "The specified path is invalid" is a typical misleading message.
    You may need to clarify the difference between "SYSTEM- User" and "Current-user "through apache. Good Luck!
    Best regards,
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

Maybe you are looking for

  • Organizing iPhoto '09 photos by year

    Hello, Can I get iPhoto 09 to group all my photos (about 10,000) by year, so that I end up with pics by year? I see that I can create a Smart Album to populate with pics taken on a specific day, but I don't see how to get it to do a full specific cal

  • How do I create an F4A file?

    [Reposting in this forum based on a suggestion from Flash Discussions] Hello everyone, I am trying to create an MP4 Audio file with the container as .f4a and I am lost. I've tried out a few products including Adobe Media Encoder CS4 and that product

  • Mac won't detect second superdrive (pics)

    so, here's the story. i flashed my macs superdrive (both of them) and after that one of them was just completely gone. when i go into system profiler and go under hawrdware and into ATA, it detects both drives, but when i go into Disc Burning, i only

  • User Rules in Data Mapping in SQL Developer Migration Workbench

    Hi I was trying to add a User Mapping Rule in the Data Mapping, because the options provided where not entirely what I wanted. Adding a new Rule for instance for SQL Server UniqueIdentifier works fine, but when I try to apply the changes it says that

  • Pricing error in the intercompany billing

    Hi, This message appear in the billing document IV " PR00 is missing". there is no problem in the order. Using analysis of the pricing, this message appear  "Conditions of category b are not permitted in company code XXX" Xhat's missing. Thanks.