I have questions about inheriting(extending) methods from classes and hiding some classes and methods from the main 🙂
Assume that I have class A & class B. Class B has method 1. and I need to use that method(method 1) in class A, but in the same time I need to hide that class(Class B with its methods) from the main.
I mean I want to deal with method 1 only from class A(or any other additional class, let’s say Class C) I don’t want it to be seen in the main. I don’t want to give the possibility for the main to create an instance from Class B to use method 1. I need to do that, because when I create a jar file for my classes, there are classes that have methods that I don’t want them to be shown. These classes I used them only when I did create the jar file.
How I can hide these classes and methods ?? I hope my explanation is clear…
Please don’t tell me to do these things, because I thought of it, and it doesn’t works : 🙂
1) to use private for the methods that I don’t want them to be shown, because I can’t do that. since, it’s a separated classes not in the same class, and when I put private near the function , I can’t use it at all, only it will works with the same class.
Also,
2) To put all the functions in the same class, Because I need to organize my code with classes with a separated files 🙂
Thanks alot Guys ….
You can solve your problem by using different packages for your classes:
Put your class containing the
main()method into packagem.Then put class
Ain packageaand make it public.Put class
Bin packagea, too and make it only package protected (skip the public key word).Now you can access class
Afrom yourmain(), but you can’t access classB.