82 - Oopexp1
82 - Oopexp1
Aim : Illustrate to create a class with member and methods by accessing the
instance variables and instance methods using dot (.) operator and
display.
Theory :
Variable in Java
o A variable is a name assigned to a value that is stored inside the system
memory. The value can be updated during the program execution.
o In Java programming, the variables used for the program need to declare
them first.
o The variable is declared using a data type followed by the identifier
name. The variable can be initialized at the time of declaration or it can
be assigned a value taken from the user during the program execution.
o There are basically three types of variables in Java,
1. Java Local variable
2. Java Instance variable
3. Java Static variable / Java class variable
Boolean false
Byte (byte) 0
Short (short) 0
Int 0
Double 0.0d
Float 0.0
Long 0L
Object null
Char \u0000
method body ;
modifier: It defines the access type of the method, and it is optional to use.
return_type: Method may return a value. Ex:- int, void, String, char, float,
etc.
method_name: This is the method name you can write anything as you
write the variable name.
method body: The method body describes what the method does with
statements.
Algorithm :
• Create a class
• Set instance variables and methods
• Access them using dot operator
Code :
Output :
Conclusion :