Object in Java || How to create an object in java? || Java OOPs Concepts Tutorials
=== Video link ===
Access Modifiers In Java : https://youtu.be/CkBCAOPdl6w
- Object is a bundle of data and its behaviour(often known as methods)
- An object in Java is any real-world things that have properties and actions.
- In other words, an entity that has state and behavior is known as an object.
- Here, state represents properties and behavior represents actions or functionality.
=== Characteristics of an object in Java ===
*** An object has three characteristics ***
1. State: State represents properties of an object. It is represented by instance variable/attribute of an object.
- The properties of an object are important because the outcome of functions depend on the properties.
2. Behavior: Behavior represents functionality or actions. It is represented by methods in Java.
3. Identity: Identity represents the unique name of an object. It differentiates one object from the other.
- The unique name of an object is used to identify the object.
=== How to Create Object in Java ===
- In Java, an object of a class is created using the new keyword in three steps. They are as follows.
1. Declaration of a reference variable.
2. Creation of an object.
3. Linking the object and the reference variable.
=== Declaration of Reference variable ===
- Basically, the declaration of an object means refers to an object. A general form of declaration of a reference variable is given below.
Classname object_reference_variable; // Creating a reference variable of type Class.
- The Classname is the name of the class which is being instantiated. The object reference variable is a variable of type Classname.
=== Creating Object in Java ===
- We can create an object in a general form like this:
new Classname(); // Creating an object of class.
- The class name followed by parentheses represents the constructor of the class.
=== Linking Object and Reference ===
- We will link the object and reference created above like this:
Classname object_reference_variable = new Classname(); // This is a syntax for creating an object of class in java.
- Assigns the new Student to the reference variable s.
Student s = new Student();
where,
Student➝ Name of the class.
s➝ Object reference variable which stores the address of the object in the stack memory.
new ➝ keyword that stores the object in the heap memory.
Student() ➝ Constructor of the class.
= ➝ The equal sign (=) is an assignment operator. It simply says to take the object created by a new keyword and assign it to the object reference variable.
- When an object of class is created, the memory is allocated in the heap area to store instance variables.
- After creation of an object, JVM produces a unique reference number (address) for that object. This unique reference number is called hash code number.
- This reference number is unique for all objects, except string objects.
- The address of the object is stored in the object reference variable in the stack memory.
- We can know the hash code number or reference number (address) of an object by using hashCode() method of object class.
- The following code can be used to know the hash code number.
=== Key points ===
- Remember that creating an object in java means allocating memory for storing data.
- You can also create an object of the class in two steps like this:
Step 1: Student s; // Declaration of reference to the object.
Step 2: s= new College(); // Creating an object.
#JavaOOPsConceptsTutorials
#LearningandTeachingCoding
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Object in Java || How to create an object in java? || Java OOPs Concepts Tutorials», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.