You are on page 1of 5

Oops :-

Global variable: The variables which are declared out of any method but inside the class are known
as Global variables.

In java we use two type of global variables:

1) Static Global variable: A global variable which is declared with keyword ‘static’ is known as Static
Global variable.

2) Instance Global variable- Variable which is declared inside the class but outside of any method
without any static keyword is known as Instance global variable or property of an object.
* Here d is a reference variable of class ‘Demo’ which is used to store a reference object.

* ‘New’ is a keyword which is used for separate memory allocation at run time.
* () it is the calling of constructor.
* new Demo- It is called memory area reference or sometime we call it an object.

Constructors are those member functions which are defined inside the class and they get
automatically called when we create an object of class. Constructor’s name is same as class
name. Constructors do not return any value. In Java we use two type of constructors:
1) Default constructor: A constructor that does not contain any argument is called default
constructor.
2) Parameterize constructor: A constructor that contain parameters in argument is called
Parameterize constructor.
*We can write more than one constructor in same java class with different length or type of
arguments is called an overloading of constructor. But when we will put two constructors
with same argument type and length in a class then compiler will produce the error at the
time of compilation. This process is called compile time polymorphism.

*When we define a class in java then compiler will write default constructor at the time of
declaration. But If user write any constructor (default or parametrize) then compiler does
not write default constructor. We cannot ever define a constructor as static. We cannot
have a constructor as static.

*Compiled form of a Java class.


Data of String class we can see with a tool javap java.lang.System;

Methods or member functions:


 Functions which are defined inside the class is called method or member function. It is
mainly used to perform a special operation within java program.

You might also like