instance of java

RSS Feed URL: http://instanceofjavaforus.blogspot.in/
Category: Java | Total Views: 1327

Latest entries from this feed

Instance variables in java with example program

Posted on 30 January 2018 | 4:57 pm by InstanceOfJava

  • Variables declared inside a class and outside method without static keyword known as instance variables.
  • Instance variables will be used by objects to store state of the object.
  • Every object will have their own copy of instance variables. where as static variables will be single and shared(accessed) among objects.
  • Instance variables will be associated with the instance(Object)
  • Static variables will be associated with the class.



#1: Java example program on declaring and accessing instance variables.

  1. package com.instanceofjava.instancevariables;

  2. /**
  3.  * @author www.Instanceofjava.com
  4.  * @category interview questions
  5.  * 
  6.  * Description: Instance variables in java with example program
  7.  *
  8.  */
  9. public class InstanceVariables {

  10. String websiteName;
  11. String category;
  12. public static void main(String[] args) {
  13. InstanceVariables obj = new InstanceVariables();
  14. obj.websiteName="www.InstanceOfJava.com";
  15. obj.category="Java tutorial/interview questions";

  16. }

  17. }


  • Instance variables allows all four type of access specifiers in java


instance variables in java with example



  • Instance variables can be final and transient


instance variables in java with example program



  • Instance variables can not be declared as abstract, static strictfp, synchronized and native



Related products