Fields And Methods In Java - RoseIndia.Net

Here we have discussed about the Fields and Methods in Java with examples and video tutorial.

Fields and Methods in Java

In this section we are discussing about Fields and Methods in Java. Fields or variables of class and Methods of a class are important while writing the Java classes. Fields can be private, protected and public.

private fields cannot be accessed outside class. public fields can be accessed anywhere. protected class cal be accessed by subclass.

Fields and Methods can also be declared static and final. When declared final, method cannot be overridden and field can be assigned a value only once.

We have also provided Video tutorial for Fields and methods in Java that will help beginners in Java to understand the topic easily and quickly. The video explains in detail the use of fields in Java, methods in Java and variables in Java.

Variables of a Class

There are three types of variables:

1. Local variables

Local Variables are defined inside methods, constructors or blocks. These variables are declared and initialized within the method and are destroyed when the method completes.

Local Variables

Here is the video tutorial of Field and Methods in Java:

Local variables are declared within the body of a function, its life is the time when method is being executed. Once method completes it execution the local variable is also removed and destroyed by JVM. Local variables are very useful if you have to perform some work in the method and don't want the temporary data.

Tag » What Are Fields In Java