RUVIDEO
Поделитесь видео 🙏

java programming , use a dog to explain the class and object concept

It is a basic unit of Object Oriented Programming and represents the real life entities. A typical Java program creates many objects, which as you know, interact by invoking methods. An object consists of :
1. State : It is represented by attributes of an object. It also reflects the properties of an object.
2. Behavior : It is represented by methods of an object. It also reflects the response of an object with other objects.
3. Identity : It gives a unique name to an object and enables one object to interact with other objects.
Example of an object : dog

Objects correspond to things found in the real world. For example, a graphics program may have objects such as “circle”, “square”, “menu”. An online shopping system might have objects such as “shopping cart”, “customer”, and “product”.
Declaring Objects (Also called instantiating a class)
When an object of a class is created, the class is said to be instantiated. All the instances share the attributes and the behavior of the class. But the values of those attributes, i.e. the state are unique for each object. A single class may have any number of instances.
Example :

As we declare variables like (type name;). This notifies the compiler that we will use name to refer to data whose type is type. With a primitive variable, this declaration also reserves the proper amount of memory for the variable. So for reference variable, type must be strictly a concrete class name. In general,we can’t create objects of an abstract class or an interface.
Dog tuffy;
If we declare reference variable(tuffy) like this, its value will be undetermined(null) until an object is actually created and assigned to it. Simply declaring a reference variable does not create an object.

Initializing an object
The new operator instantiates a class by allocating memory for a new object and returning a reference to that memory. The new operator also invokes the class constructor.
package ch3cw_dog;

public class Dog {
// declare variable - state, attribute
String name;
String breed;
int age;
String color;

// default constructor
public Dog()
{
name ="Best Friend";
breed ="labrador" ;
age =0;
color = "white";

}
// mutate constructor
public Dog(String n, String b, int a, String c)
{
name = n;
breed = b;
age = a;
color =c;

}
public String getName()
{
return name;
}
public String getBreed()
{
return breed;

}
public int getAge()
{
return age;
}
public String getColor()
{
return color;
}
public String toString()
{
return("Hi my name is " + getName() + "\nMy breed , age and color are " + getBreed()+" , " + getAge() + " , "+ getColor());
}

}
package ch3cw_dog;

public class UseDog {

public static void main(String[] args) {
Dog defaultDog = new Dog(); // use default value
Dog dogForErber = new Dog("Blackie","Yorkie",2,"Brown");

System.out.println("Display a default dog");
System.out.println(defaultDog.toString());
System.out.println("Display a dog for Erber Espinoza");
System.out.println(dogForErber.toString());


}

}

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «java programming , use a dog to explain the class and object concept», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.