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

Java - 9 | Static variables | Static blocks | Static methods смотреть онлайн

📁 Лайфстайл 👁️ 17 📅 05.12.2023

Static variables are declared with the static keyword in a class, but outside a method, constructor or a block.
There would only be one copy of each class variable per class, regardless of how many objects are created from it.
Static variables are stored in static memory. It is rare to use static variables other than declared final and used as either public or private constants
Static variables are created when the class containing static variables is loaded and destroyed when the program stops.
Visibility is similar to instance variables. However, most static variables are declared public since they must be available for users of the other classes.
Static variables can be accessed by calling with the class name
ClassName.VariableName
Default values are same as instance variables.
For integers the default value is 0, for Booleans it is false and for object references it is null.
Values can be assigned during the declaration or within the constructor.
Additionally values can be assigned in special static initializer blocks
// Java program to demonstrate use of static blocks
class Test
{
// static variable
static int a = 10;
static int b;

// static block
static {
System.out.println("Static block initialized.");
b = a * 4;
}
public static void main(String[] args)
{
System.out.println("from main");
System.out.println("Value of a : "+a);
System.out.println("Value of b : "+b);
Output : -
Static block initialized.
from main
Value of a : 10
Value of b : 40

Static variable example 2
class Student
{ String name;
int rollNo;
// static variable
static String cllgName;
/ /static counter to set unique roll no
static int counter = 0;
public Student(String name)
{
this.name = name;
this.rollNo = setRollNo();
}
// getting unique rollNo
// through static variable(counter)
static int setRollNo( ) {
counter++;
return counter;
}

}
}


static void setCllg(String name){
cllgName = name ; }
// instance method
void getStudentInfo(){
System.out.println("name : " + this.name);
System.out.println("rollNo : " + this.rollNo);
// accessing static variable
System.out.println("cllgName : " + cllgName);
} }
public class StaticDemo {
public static void main(String[] args) {
// calling static method without instantiating Student class
Student.setCllg("XYZ");
Student s1 = new Student("Alice");
Student s2 = new Student("Bob");
s1.getStudentInfo();
s2.getStudentInfo();
}
Output : -
name : Alice
rollNo : 1
cllgName : XYZ
name : Bob
rollNo : 2
cllgName : XYZ

Strongly typed Language
Java is a strongly typed programming language because every variable must be declared with a data type.
A variable cannot start off life without knowing the range of values it can hold, and once it is declared, the datatype of the variable cannot change.
Example : - boolean b;
For the rest of its life, b can only ever have a value of true or false.

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Java - 9 | Static variables | Static blocks | Static methods» бесплатно и без регистрации, вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

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

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

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