💻 Step 4: Classes & Objects -Unlock Java Fundamentals in Your 2nd Hour

Get this in action on youtube-

FeatureClassObject
DefinitionA class is a blueprint or prototype for creating objects.An object is an instance of a class. It is a real-world entity that has state and behavior.
Syntaxclass ClassName {  
// fields  
// methods
}
ClassName objectName = new ClassName();
Exampleclass Car {  
int modelYear;
String modelName;
void startEngine() {

}
}
Car myCar = new Car();
PropertiesA class has properties such as fields and methods.An object has properties such as its state (the values of its fields) and behavior (the methods it can perform).
Memory allocationA class is not physically stored in memory.An object is physically stored in memory.

💡Class

Definitions- 

💡 -> Class is a blueprint or template from which objects are created.

💡 -> Class is a logical representation of object.

💡 -> A class can have data members, objects, constructors, methods, nested classes etc

💡 -> Class doesn’t allocated memory when it is created.

💡 -> Class defines data members and methods which objects can implement.

Syntax –


class className{

}

 

💡Object

Definitions-

💡-> Object is an instance of a class

💡-> Object is considered as a real world thing.

💡-> Object is a physical entity.

💡-> Object uses data/state and methods/behaviour.

💡-> Object allocates memory when it is created.

Syntax(in general)-

ClassName objectName= new ConstructorName();

Note- ways to create object in java – new keyword(most popular), newInstance() method, clone() method, factory method and deserialization.

Interview Questions —

  • What is class in real world example?
  • Can object be created without class?
  • Who uses all methods and data defined in any class?

One comment

  1. […] Step 4: Classes & Objects – Unlock Java Fundamentals (2nd Hour)Step 5: Java Datatypes Explained – Easy Guide with Code (2nd Hour)Step 6: Java Constructors Explained – Easy Guide with Code (3rd Hour)Step 7: Java Variables Explained – Easy Guide with Code (4th Hour)Step 8: Java Modifiers Explained – Easy Guide with Code (5th Hour)Step 9: Java Operators Explained – Easy Guide with Code (6th Hour)Step 10: Java Type Casting and Boxing Explained – Easy Guide with Code (6th Hour) […]

Leave a Reply

Your email address will not be published. Required fields are marked *