You can learn Java with me as the Java Programming language is being made easily. It would take a period of minimum three months and maximum 6 months to master Java. I would recommend you to watch all my videos to crack any software interviews that would require Java Programming language as a primary skill.
control flow of static and instance context in Java:-
=========================================================
1. static context:-
==================
static blocks and static variables are automatically recognized and executed at the time of loading the .class file to the JVM.
However, the static methods are executed only during the method call.
Please be informed that the .class file will be loaded inside the JVM only once. At the time of loading the .class file, the static variables and blocks will get recognized and executed automatically.
2. instance context:-
=====================
The instance variables and blocks are recognized and executed before executing the respective class constructor.
However, the instance methods are recognized and executed at the time of method call with the object reference.
Please be informed that the instance methods and blocks will be recognized and executed every time the respective class constructors are called.
Examples:-
=========
package xyz;
public class Test
{
static int a=method1();
static int method1()
{
System.out.println(" M1");
return 1000;
}
static{
System.out.println("S A 1");
}
static{
System.out.println("S A 2");
}
public static void main(String[] args)
{
}
}
Examples:-
========
package xyz;
class C{
static{
System.out.println("S B C");
}
}
class A extends C
{
static{
System.out.println("S B A");
}
}
public class Test extends A
{
static{
System.out.println("S B");
}
public static void main(String[] args)
{
}
}
Examples:-
=========
package xyz;
public class Test
{
static{
System.out.println("S B");//It will be recognized at the time of loading the .class //file to the JVM
}
{
System.out.println("I B");//Before the respective class constructor
}
Test()
{
System.out.println("T Con ");
}
public static void main(String[] args)
{
new Test();
new Test();
}
}
На этой странице сайта вы можете посмотреть видео онлайн static context and instance context control flow in Java the complete explanation длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Learn Java 19 Апрель 2024, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 161 раз и оно понравилось 5 зрителям. Приятного просмотра!