A Deep Dive into Classes, Methods, Variables, and Modifiers
Demystifying Java Basics
Class :-
Class is a sketch used to implement an object at the programming level. And also we an define class as "A template that can keep the things what we need" .It is a blue print of a object.
We take only the class, the constructor and main method as the limits of the class. Although the other methods are inside the class, we do not take them as the boundary of the class.![]() |
Variables are containers for storing data values. Mainly there are two types in variables.
Static Variables-
When a variable is declared static in Java programming, it means that the variable can access any place in the class. We cant convert local variables as static variable.
We use "static" keyword for that variables.
Non-static Variables-
Non-static variables can only be accessed by creating an instance of the class. In there no keyword use like "static". We can divide non-static variable as "Local" and "Instance" variable.
Local Variable - A variable declared inside the body of the method is called local variable. You can use this variable only within that method.
Instance Variable - If any variable inside boundary of the class, we call that variables as Instance variable.
Methods :-
A method in OOP is a block of code that, when called, performs specific actions mentioned in it.
Pre Defined Methods - Predefined methods in Java refer to those that are predefined and previously defined in the Java class libraries. It is sometimes referred to as the built-in approach or the standard library method. By just invoking these methods at any time during the program, we can use them immediately.
User Defined Methods - These methods are create by user. User can create method for his usage.
Main Method :-
The Java main method is usually the first method you learn about when you start programming in Java because its the entry point for executing a Java program. The main method can contain code to execute or call other methods, and it can be placed in any class that's part of a program.
Modifiers :-
Modifiers are keywords that you add to those definitions to change their meanings. Java language has a wide variety of modifiers.
- The static modifier for creating class methods and variables. We can use it any place of the class. We can call it without object or access.
- The final modifier for finalizing the implementations of classes, methods, and variables.
- The abstract modifier for creating abstract classes and methods.
- The synchronized and volatile modifiers, which are used for threads.
- Visible to the package, the default. No modifiers are needed.
- Visible to the class only (private).
- Visible to the world (public).
- Visible to the package and all subclasses (protected).
Comments
Post a Comment