Hi to all,
mailmy all methods are public.but in some case we are using the protected methods and private methods.
when do we make methods private (or) Protected ?
could u plz give me a clarification
Hi to all,
mailmy all methods are public.but in some case we are using the protected methods and private methods.
when do we make methods private (or) Protected ?
could u plz give me a clarification
hii Naresh,
yes we can make methods private and protected…
The main use of private method is to hide the logic from child class when ever we inherit it with the parent class.
Use protected is for showing the logic to the next child class not to other child classes…
For Example :
i have a class Test and i have two methods one is private void hello(){} and second is protected void testing(){}. Suppose i have a class Tested which inherits parent class Test which is having two methods one is private and another is protected .
Class Tested extends Test
{
}
if you want to access a protected method of Test class you can access that method by using
Test test = new Test();
test.testing();
but if you wabt to access a private method of Test class you can’t access that method…
hii Naresh,
yes we can make methods private and protected…
The main use of private method is to hide the logic from child class when ever we inherit it with the parent class.
Use protected is for showing the logic to the next child class not to other child classes…
For Example :
i have a class Test and i have two methods one is private void hello(){} and second is protected void testing(){}. Suppose i have a class Tested which inherits parent class Test which is having two methods one is private and another is protected .
Class Tested extends Test
{
}
if you want to access a protected method of Test class you can access that method by using
Test test = new Test();
test.testing();
but if you wabt to access a private method of Test class you can’t access that method…