Classes Object and Variable in Java with Simple Examples - Java2021 : Online Tutorials Hub

Java2021 : Online Tutorials Hub

JAVA | Advance Java | MySQL | Data Structure | Git | HTML | CSS | JS

Latest

Post Top Ad

Friday, June 19, 2020

Classes Object and Variable in Java with Simple Examples

Learn classes and object in java with examples

What is Class : It is a template or blueprint which object are created. and it is a group of object which have common property.
What is Object : Object is a real world entity like pen,book,stool,copy,apple,peas and more are real word entity. object oriented programming we create a everything in object.

Properties of Class : 

Class have this properties

  • Field
  • Methods 
  • Constructor
  • Block
  • Interfaces
  • Nested Class
Syntax of Class : 
public class class_name 
{
//class bod
}
Example of Class 
public class Car

public static void main(String []args){
System.out.println("This is class example");
}
}


Point to Remember before creating a class
  • Class name always capital latter
  • Access modifier is option to use in class
  • Main class always make with main method
  • Class may have variable,methods,constructor etc. 
  • Class may have  inner class and interfaces
  • Class may have static method, static variable etc.
Variable : Hold/Store the data is called variable.
Types of variable  :
  1. Variables defined inside methods, constructors or blocks are called local variables.
  2. A variable which is created inside the class but outside the method, is known as instance variable.
  3. Class variables are variables declared within a class, outside any method, with the static keyword
Creating a Object in Java
  • By new keyword
  • By newInstance() method
  • By deserialization
  • By clone() method
  • By factory method etc.
How to Initialized object in Java : Initializing object simply means storing data into object.We can also create multiple objects and store information in it through reference variable.
  1. By Reference Variable
  2. By Constructor
  3. By Methods
Click to next  : How to Create Class Object and Variable With This Simple Example.

-------------------------------------------------------------------------------------------------
Start with your Choice
-Important Programs for Freshers
Sorting and Searching Programs
Learn Pattern Programs
Click to learn Array Programs
Click to Learn MySQL 
for any complaint regarding my Blog please visit contact us page and write what problem you have!

No comments:

Pages