Yes, but not in a normal way.
Sample code:
namespace WikiAnswers {
public class MainClass {
protected class HereItIs {}
}
}
The inner class MainClass.HereItIs is the answer to this question.
If you change the accessibility of MainClass from public to protected, the compilation will fail.
My interpretation of the keyword protected is: "accessible to the class itself and its derived classes", and may only decorate/mark it to class elements (data members, methods, properties, etc.)
Noramlly, we declare a class as a namespace element, e.g. MainClass above, I almost answered 'NO' to this question when I read the question the first time. Tricky.
The above example may be applicable to Java:
1. replace namespace to package
2. the rest of the codes should be the same
no, java does not support a class declared as private. Because of java's high security java virtual machine [jvm] does not allow any data to be declared as private. infact, java has its own codes that are private to itself and thus cannot be accessed by any of us.
yes it is possible to make a private class in C++ but this class will not solve any purpose.................
If you declare the main method anything other than public, it will not run. If you declare main method as private, you would not be able to execute the class as a standalone java program. Any java class that needs to be executed as a standalone file needs to have a main method that is public, static and returns a void. Otherwise the Java compiler would not recognize the file as an executable standalone java file and would not allow you to run it.
A member function of a class can be defined outside the class using scope resolution :: operator Thanks Rajneesh
In Flex, you access a private variable by calling it from within that class. Remember, the "private" modifier means it cannot be directly accessed outside of the class you declare it in (note I say "directly accessed" you can indirectly access it via public functions which I will show below). Example: declare your variable at the top of your class like this: private var myVariable:String; Then, inside one of your functions of that class, you can access the variable and/or assign it this way: public function changeMyVariable(value:String):void { // sets the private variable to a custom string myVariable="test String"; trace("myVariable is set to "+myVariable); // sets the private variable to the argument passed in myVariable = value; trace("myVariable is now set to" +myVariable); }
Friend functions (and classes) have private access to the classes that declare them as friends. Although they have the same access rights as members of the class itself, friends are not themselves members of the class and cannot be inherited.
yes it is possible to make a private class in C++ but this class will not solve any purpose.................
If you declare the main method anything other than public, it will not run. If you declare main method as private, you would not be able to execute the class as a standalone java program. Any java class that needs to be executed as a standalone file needs to have a main method that is public, static and returns a void. Otherwise the Java compiler would not recognize the file as an executable standalone java file and would not allow you to run it.
You can declare and implement a class within a class...class abc {...class def {...}}The class def is scoped and known only within the context of abc. It is possible to declare instances of def as member variables of abc, however, for this to work correctly, they should be private, because methods of def, not even public methods, do not exist outside of the scope of abc.
Yes, but that means you can't define an instance of the class without arguments to new.
A friend is any class, class method or function that is declared to be a friend of a class. Friends have private access to the classes that declare them friends.
Public members in C++ have accessibility to any function that has scope to the instance of the class, whereas private members have accessibility only to functions of that class.
A member function of a class can be defined outside the class using scope resolution :: operator Thanks Rajneesh
Declare it final.
class Rectangle{ private: int length; int width; public: void input(); void output(); };
Private variables can only be accessed from outside of a class by using any public function of that same class. Or this can be accomplished by using Friend functions.
In Flex, you access a private variable by calling it from within that class. Remember, the "private" modifier means it cannot be directly accessed outside of the class you declare it in (note I say "directly accessed" you can indirectly access it via public functions which I will show below). Example: declare your variable at the top of your class like this: private var myVariable:String; Then, inside one of your functions of that class, you can access the variable and/or assign it this way: public function changeMyVariable(value:String):void { // sets the private variable to a custom string myVariable="test String"; trace("myVariable is set to "+myVariable); // sets the private variable to the argument passed in myVariable = value; trace("myVariable is now set to" +myVariable); }
You don't need a typedef to declare a struct in C++. A struct is declared exactly the same way that you would declare a class, the only difference being that struct members are public by default, while class members are private by default. Aside from that the class and struct keywords are completely interchangeable.