Search...

Saturday, December 20, 2014

Types of Variable in JAVA? Is JAVA a pure object oriented programming language?

A class can contain any of the following variable types.

Local variables : variables defined inside methods, constructors or blocks are called local variables. The variable will be declared and initialized within the method and the variable will be destroyed when the method has completed.

Instance variables : Instance variables are variables within a class but outside any method. These variables are instantiated when the class is loaded. Instance variables can be accessed from inside any method, constructor or blocks of that particular class.

Class variables : Class variables are variables declared with in a class, outside any method, with the static keyword. 


JAVA is not a pure object oriented programming language because in C++ we know that in class, during declaration of variable, initialization is not allowed because it is an instance variable & their is no memory allocation. 


But in JAVA we can initialize the value like:


class abc

{

int a=10; //it is allowed in java for this it is not pure oop

}


but  in c++

class abc

{

int a=10; //it is not allowed 

}




No comments:

Post a Comment