I have just learned about classes and objects in Java. I just thought to share it with you all about it.
What is Class:
Class is a blueprint/Template which defines the structure and behaviour of something.
Class is a JAVA Keyword. It is called a "logical Entity" because it is only a blueprint and does not occupy memory until an object is created.
Syntax follows:
class ClassName{
}
- First letter should be in uppercase, and it only allows special characters like $ and _. Also, numeric values are allowed only in the middle and last.
What is Object:
- An object is a combination of state and behaviour. Where the state represents the properties or features of the object, while behaviour represents what the object can do. For example, a Car object has a color and speed (state) and can drive or brake (behaviour). Syntax as follows:
ClassName referenceName = new ClassName();
If we mention a new keyword in an object, JVM will create a memory in the heap at run time, and this is why "It is called a "Physical Entity".
More posts coming soon!!
Top comments (0)