Object in JAVA

Objects in java

Java object

A house, motorcycle, truck, notebook, sofa, or computer are examples of objects. An object is any item with state and activity. It could be mental or physical (tangible and intangible). An example of an intangible entity is the financial system.

More on Java Objects :

Everything in Java is built upon the objects and classes, as well as their traits and methods. A truck, for example, is an entity in the actual world. Along with features like accelerate and break, the truck also has qualities like mass and colors.
Any kind of class can have an object as an instance.
Classes are logical constructs, whereas objects are the physical manifestations of a class, and these are the things that are actually taking up memory space.

Objects are categorized into three types:

object in java

 

How to create a class :

To create a object of any class , we use the new keyword . This new keyword create the object at runtime.

Example :

Classname objectName = newKeyword classname();

Run

class Boxers {
//.....variables...
//.....methods.....
}
public class Main public static void main(String [] args){ //creating new object of class type Boxers Boxers var = new Boxers(); } }

Ways to Initialize  an Object

  1. Parent to parent reference.
  2. Parent to child reference.
  3. Child to child reference.

Code Example :

Run

class Boxers {
//.....variables...
//.....methods.....
}
class RedBoxer extends Boxers{
//This class contains all the features of class Boxers.
}
public class Main{ public static void main(String [] args){ //parent to parent Boxers var = new Boxers(); //parent to child Boxers var1 = new RedBoxer(); //child to child RedBoxer var2 = new RedBoxer(); } }

Prime Course Trailer

Get PrepInsta Prime & get Access to all 200+ courses offered by PrepInsta in One Subscription

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others

Checkout list of all the video courses in PrepInsta Prime Subscription

Checkout list of all the video courses in PrepInsta Prime Subscription