Wednesday, 13 April 2016

KEYWORDS IN JAVA

                                       KEYWORDS


            In java there are more than 42 keywords and still finding, Here I'll get you through the main three concepts on keywords,
                                                               *   This
                                                               *   Super
                                                               *   Static

THIS KEYWORD:

           This is the keyword used to refer the current class objects in java, It invoke the current class constructor , current class methods and the current class variable. This is used to specify the variable when the compiler got confused , 
             
            For example if there are 3 users called A, B, C, The user A and B simultaneously give the data to C and C gets confused that which data from the users. In this situation we use THIS keyword to specify the person.

            There are three type of THIS keyword is used they are 

          "   this()- It is used to invoke the current class constructor,
              this.a()- It is used to invoke the current class method,
              this.a - It is used to invoke the current class variable.  "

           Example:

                                                Public class ThisEx
                                                   {
                                                      int a=5;
                                                   ThisEx()
                                                   {
                                                    }
                                                     ThisEx(int a)
                                                    {
                                                     }
                                                      void a()
                                                   {
                                                          }
                                                   void b()
                                                      {
                                                       this.a();
                                                       system.out.println(this.a);
                                                          }
                                                        public static void main (String args[])
                                                    {
                                                       ThisEx obj=new ThisEx(5);
                                                            obj.b();
                                                          }
                                                              }

             By using THIS keyword it have certain rules. While invoking this() that invocation should be inside the constructor .While invoke the this.a() that invocation should be inside the method. While invoke the this.a that invocation should be inside the statement. 

SUPER KEYWORD:

            Super keyword is used to refer the super class object. It is used to invoke the super class constructor, super class methods, super class variables.

            Super is used to get the specific content from the super class, There are three types of super method are used they are,

                  "  Super()-- It is used to invoke the super class CONSTRUCTOR.
                    Super.a()-It is used to invoke the super class METHOD.
                    Super.a-- It is used to invoke the super class VARIABLE   "


          Example:

                                                          Class super1
                                                        {
                                                          int a=5;
                                                          super1()
                                                       {
                                                          system.out.println(super class constructor);
                                                          }
                                                         void.a()
                                                         {
                                                         system.out.println(super class method);
                                                         }
                                                              }
                                                         public class SuperEx extends Super1 
                                                          {

                                                             SuperEx()
                                                         {
                                                               super();
                                                            }
                                                               void b()
                                                         {
                                                               super.a();
                                                              system.out.println(super.a);
                                                            }
                                                               public static void main(String args[])
                                                          {
                                                                superEx obj=new SuperEx();
                                                                 obj.b();
                                                              }
                                                                 }

            By using the super keyword it have certain rules. While invoke the super() that invocation  should be inside the constructor.While invoke the super.a() that invocation should be inside the method. While invoke the this.a that invocation should be inside the statement.

STATIC KEYWORD:

            Static keyword is used to run the static content first. While declaring the static method and static variable in the program, without the help of the object it is possible to call the methods and variable inside the main method.
             By defining the static method it uses only the static variable

      Example:
 
                                                      public class Example
                                                 {
                                                      static int a=5;
                                                      static void a()
                                                 {
                                                       system.out.println(a);
                                                   }
                                                       public static void main(String args[])
                                                 {
                                                       a();
                                                   }
                                                 }
Well here we seen the full indeapth concept of the KEYWORDS in Java, with some practical programs, try it in your environment and learn this easily  . Do comments for better up-gradation and further post

                                            COMMENTS PLS................... 

No comments:

Post a Comment