- JAVA OVERVIEW
- History of Java
- Tools you will need for java
- Java Environment Setup
- Popular Java Editors
- Java Basic Syntax/First-Program
- Java Identifiers
- Java Modifiers
- Java Arrays
- Java Enums
- Java Keywords
- Comments in Java
- Java - Objects and Classes
- Objects in Java
- Classes in Java
- Constructors
- Creating an Object
- Accessing Instance Variables and Methods
- Source file declaration rules
- Java Package
- Simple Case Study
- Basic Data Types
- Primitive Data Types
- Reference Data Types
- Java Literals
- Variable Types
- Local variables
- Instance variables
- Class or static variables
- Java Access Modifiers
- What is OOPS
- Inheritance concept
- Encapsulation
- What is Polymorphism
- Method Overloading
- Method Overriding
- Abstraction in Java
- Abstract class
- Interface in Java
- Method overloading in Java:
- What is Annonymous object?
- Java 8
How to create Object in Java?
As mentioned previously, a class provides the blueprints for objects. So, basically an object is created from a class. In java, the new keyword is used to create new objects.
There are three steps when creating an object from a class:
Declaration . A variable declaration with a variable name with an object type.
Instantiation . The 'new' key word is used to create the object.
Initialization . The 'new' keyword is followed by a call to a constructor. This call initializes the new object.
Example of create an object in Java:-
public class Puppy
{
public Puppy(String name)
{
// This constructor has one parameter, name.
System.out.println("Passed Name is :" + name );
}
public static void main(String[] args)
{
// Following statement would create an object myPuppy
Puppy myPuppy = new Puppy( "tommy" );
}
}
If we compile and run the above program then it would produce following result:
Passed Name is :tommy