Skip to main content

Simplify Your Tax Calculations with GST Calculator 2024: The Ultimate Tool for Businesses and Individuals

Understand the concept of Java Classes and Objects with an example | Class | Object | Java

 In this article, We try to understand the concept of Java Classes and Objects with an example. The key content of this article are-

(i) What is class and Object

(ii) Example of class and object

(iii) Difference between Class and Object

(i.a) Class In Java:

A class is an entity that determines how an object will behave and what the object will contain. In other words, it is a blueprint or a set of instruction to build a specific type of object. It provides initial values for member variables and member functions or methods.

(i.b) Object In Java:

An object is nothing but a self-contained component that consists of methods and properties to make a data useful. It helps you to determines the behaviour of the class.


i.e we say that "A class is a template for an object, and an object is an instance of a class". That's why class is called as logical entity, where object is physical entity.  So simply, a class does not allocate memory space when it is created, on other hand, Object allocates memory space whenever they are created.

(ii) Example of class and object:

The OOPS concept is inspired by nature, and if we compare it with our real life world, if we consider what is the difference between Animal and set of animal type say tiger, lion, cat, cow etc.

Simply Animal we say class and tiger, lion, cat, cow are the instance of the animal, i.e we say object.


Example in code:

Animal class: is contain 3 member variable height,weight,color and 2 member function sleep() and eat().

class Animal {
  	int height = 5;
  	int weight =10;
  	String color="black";
  	
  	private void sleep(){
  	
  	}
  	
  	private void eat(){
  	
  	}
}

Object: instance of class

Animal tiger=new Animal();
Animal lion=new Animal();
Animal cat=new Animal();
Animal cow=new Animal();


(iii) Difference between Class and Object:
ClassObject
A class is a template for creating objects in program.The object is an instance of a class.
A class is a logical entityObject is a physical entity
A class does not allocate memory space when it is created.Object allocates memory space whenever they are created.
You can declare class only once.You can create more than one object using a class.
Class generates objectsObjects provide life to the class.
Classes can’t be manipulated as they are not available in memory.They can be manipulated.
It doesn’t have any values which are associated with the fields.Each and every object has its own values, which are associated with the fields.


















Comments

Popular posts from this blog

How to fetch Latitude, Longitude from address and vice-versa(address from Latitude, Longitude) using Google Geo coder SDK in android| Kotlin

 In this Android development related article, you will get a simple solution that, how to get address using Latitude, Longitude and vice-versa. i.e latitude, longitude from an address text. It is very easy and simple. Read full article and carefully follow all the steps. Here we use google Geocoder SDK. Okay, first we create an android project in kotlin and create an Activity say MainActivity.kt. Use the below code- Function get Latitude, Longitude from Address- fun getLatLngFromAddress (context: Context, mAddress: String): String { val coder = Geocoder(context) lateinit var address: List<Address> try { address = coder.getFromLocationName(mAddress, 5 ) if (address == null ) { return "Fail to find Lat,Lng" } val location = address[ 0 ] return " Latitude: ${location.latitude}\n Longitude: ${location.longitude}" } catch (e: Exception...

How to consume REST APIs in Laravel | Laravel Development | Solution

In Laravel, you can call a REST API using the HTTP client provided by the framework. Laravel's HTTP client allows you to make GET, POST, PUT, DELETE, and other HTTP requests to external APIs. Here's how you can call a REST API in Laravel: Install Laravel (if not already done): If you haven't already set up a Laravel project, you can create one using Composer by running the following command: composer create - project -- prefer - dist laravel / laravel project - name Create a Controller (optional): You can create a controller to encapsulate the API call logic, but this step is not strictly necessary. You can also make API calls directly from your routes or other parts of your application. To create a controller, run the following command: php artisan make: controller ApiController Make an API Request: You can make API requests using Laravel's HTTP client, which is a fluent, expressive interface for making HTTP requests. Here's how you can make a simple GET request t...

Create Any Recyclerview Adapter within 5 seconds, in Android | Kotlin.

 In every single android application, we need to make many number of recycler-view adapter. So every time you create a blank adapter and modify it as per your requirements. But it is very boring and as well as time taking. So here I give you a solution that you can create any recyclerview adapter within 5 seconds using file template in Android Studio. So, Lets read this full article- First we open android studio and create a project. After project creation  Open File->new->Edit File Template... Follow this below screenshot Okay, After click on "Edit File Template" a popup is open "File and Code Template", Now click on the  " + " icon and set set your template name. Now set your template name, template extension and template body. after doing everything click on "Apply" and then click on "OK" The template body I after after the screenshot Template Body Copy this code and paste it on the template body section, which I marked in scre...