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

Java 20 | Types of constructors | Default constructor | No arg Constructor | Parameterized Construt

Types of constructors
Default constructor
No – arg Constructor
Parameterized Constructor
1 Default constructor
If you do not define any constructor in your class, java defines one for you by default. This constructor is known as default constructor.
class Demo {
}
after compilaton : -
class Demo {
Demo( ) { } // default constructor
}

Purpose of constructor is to initialize the instance variable
But default constructor has nothing in code so it initializes the instance variables with their default values ( like 0, 0.0, null ) depending on their type ( for integer 0, for string null)

class Demo {
int id;
String name;
int age;
void show (){
System.out.println(id + “ “+name+” “ +age);
}
public static void main( String args[]) {
Demo d =new Demo();
d.show();
}
}
output: 0 null 0

2 No-arg constructor
constructor with no argument is known as No-arg constructor.
the signature is same as default constructor, however body can have any code unlike default constructor where the body does nothing.
Ex:-
class Demo {
Demo ( ) {
System.out.println(“this is No_arg constructor”);
}
}

3 Parameterized Constructor
You can send parameter to the constructor just like a method.
class Demo{
Demo(int a, int b){
// statements
}
}

class Rectangle {
int length, width;
Rectangle (int l, int w){
length =l;
width =w;
}
}
Rectangle r =new Rectangle( ); wont compile no matching constructor
Rectangle rr= new Rectangle(5,4); will compile, arguments matched


Method :-
1) Method can be any user defined name
2) Method should have return type.
3) Method should be called explicitly either with objec reference or class reference
4) Method is not provided by compiler in any case.

Constructor: -
1) Constructor must be a class name.
2) It should not have any return type (not even void)
3) It will be called automatically when an object is created.
4) Java compiler provides a default constructor if we do not have any constructor

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Java 20 | Types of constructors | Default constructor | No arg Constructor | Parameterized Construt», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

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

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

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