Posts

Showing posts from August, 2017

How Method Overloading Helping in Java - Part 9

I'm sharing my experience with you as these are the questions which have been asked to me while interviewing on java profile. Where have u observed method overloading helped us in java? Where have you seen in java default classes using method overloading? We need method overloading because if we have multiple arguments for add method and we have to create multiple methods in that case we will be confused which method to call to perform specific addition. Example: class   PrintOverloading1 {      public   void  show( char  c)     {           System . out .println(c);     }      public   void  show( char  c,  int  number)      {           System . out .println(c +  " " + number);     }    public   void  show( char  c,  String s )      {           System . out .println(c +  " " + s);     } } class   demo1 {     public   static   void  main( String  args[])    {         PrintOverloading1 obj  =  new   PrintOv

Access Modifiers in java

Access Modifiers in Java Access to classes is controlled using Access Modifiers aka ( Access Specifiers, Visibility Specifiers ) in java. These are used to regulate access to classes, fields and methods in java. Using access modifiers you can control the access of variables, methods with in a class. Java provides number of access modifiers to control the access for class as well as the fields, methods and constructors in your classes. We have 4 types of access modifiers in java which are explained below:- Default: Visible to the package, the default. No modifiers are needed, no keyword is required. Private: Visible to the class only. Public: Visible to the world. Protected: Visible to the package and all subclasses. Default: We do not have any default specifier in Java. It provides Default specifier which is used where no access modifier is present. Using this you can access class, methods or fields which belongs to same package, but not from outside