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.
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
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 :
- Variables defined inside methods, constructors or blocks are called local variables.
- A variable which is created inside the class but outside the method, is known as instance variable.
- 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.
- By Reference Variable
- By Constructor
- By Methods
Click to next : How to Create Class Object and Variable With This Simple Example.
-------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------
Start with your Choice
-Important Programs for Freshers
- Palindrome Number
- Prime Number
- Swapping Number
- Leap Year
- Odd and Even Number
- Fibonacci Series
- Armstrong Number
- Factorial Number
- Print Table
Sorting and Searching Programs
Learn Pattern Programs
Click to learn Array Programs
- 4 ways to print Array in Java
- 2D Array in Java
- Anonymous Array in Java
- Single Dimensional Array in Java
- Find Second Largest Number in Array
- Delete an Element in Array in Java
- Common Element in Array in Java
- Missing Element in Array
- Insert Element in Array
- Smallest and Largest Elements in Array
- Find Odd and Even Number in Array
Click to Learn MySQL
for any complaint regarding my Blog please visit contact us page and write what problem you have!
No comments:
Post a Comment