+ 2

What is difference between package of java and header files of C or C++ ?

25th Dec 2016, 12:15 PM
Ajay Agrawal
Ajay Agrawal - avatar
4 Respostas
+ 5
Thank you for aid. can you explain in some deeply?
25th Dec 2016, 1:30 PM
Ajay Agrawal
Ajay Agrawal - avatar
+ 4
I got one difference only it is that we can access all methods or one method by package in java at a time, but in header files such type used of facilities are not possible.
25th Dec 2016, 12:21 PM
Ajay Agrawal
Ajay Agrawal - avatar
+ 1
Header in c++ is for declaring methods. In that regard, an analogy in Java would be an interface class, not a package. Package is just a group of classes. Using modifier protected allows visibility to all classes in the package.
25th Dec 2016, 1:29 PM
Eva
Eva - avatar
+ 1
Header files, as well as interfaces are used, when you have more classes with same methods that are implemented differently in each class. It basically saves time with declaring same methods in each class you want to use them in. You just implement them. When you have bigger project in Java, it's better to put classes in different packages depending on what they do in the program. When you want to create an instance of a class A in different class B that is not in the same package, you need to import A to B. If both classes A and B were in the same package, import would be unnecessary. Both classes would also have access to methods and parameters of other class that would be declared with privacy modifier protected.
25th Dec 2016, 1:54 PM
Eva
Eva - avatar