CORE JAVA PART 2

10.STATIC 
11.THIS
12.FINAL


STATIC:
*******
  whenever we declare the some properties with in a class,
 if we want to access those properties we have to create object
 s to that class.such type of properties is called instance property.
 for those properties values are different from one object to 
 another object but properties are common.in some cases,properties
  as well as their values are common to any object.so we cannot
  use objects to call those properties.we have to use class name
  to invoke static members.

 **'THIS' object is cannot be applied to  the static members.**

  static members are two types:
   1.static variables
   2.static methods
 these are shared by all objects because of these are stored in
 common memory.normal variables are stored in object memory.

  static type variable;
  static type method();


program:

 //any program 


THIS:
******
 it is an implicit,dynamic,generic object to store the
 address which is of currently executing object.
 it is used to differentiate local variable with member
 variable,if both of these variables having same name. 
 we have to place 'this' keyword before the member variable name.

 It is used in two contexts 1.to differentiate the two objects
       2.constructor calling from another constructor.

  program: // any program for one.
     // any program for two.


final:
******
 1.final is a key word to create constants in java as like constant keyword in c.
 2.to avoid member overriding ,we have to use final keyword before the parent class
  member method.
 3.to make a class as terminal class i.e. if you see final keyword before the 
  class name,we cant create child class to that class.

  final int a=34;
  final void method(){}
  final class class-name{}
 -------------------
  final int a;// invalid because value should be give
  final method();// definition required.
 -------------------
  

  class parent
  {
   final void show(){}
  }
  class child extends parent
  {
   void show(){} // error is displayed.
  }

 --------------------
  final class parent
  {
   //body
  }
  class child extends parent // this is the error
  {
  
  }

No comments:

Post a Comment