Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
dTub
Скачать

Selenium automation testing course with Java-static and final keywords in java- class 13

Автор: Learn Java

Загружено: 2025-06-27

Просмотров: 116

Описание:

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.

class 13:
========
continued from class 12

3. Pass current object as a parameter
Useful when you need to pass the current object to a method or constructor.
public void display(Student s) {
System.out.println(s.name);
}
public void show() {
display(this); // passing current object
}
Return current object from a method
4. Allows method chaining.
======================
public class Student {
public Student getStudent() {
return this;
}
}
5. Access current class methods
===============================
Though implicit, you can use this to call methods within the same class.
public void show() {
this.display(); // same as display()
}
public void display() {
System.out.println("Hello");
}
static context in java:-
==================
Static Context = Class-Level Context
When you declare something as static in Java, it is shared among all instances of that class and can be accessed without creating an object.

Examples of Static Context
======================
Static variables:
============
Static variables are recognized and executed at the time of loading the byte code to the memory.
class MyClass {
static int count = 0; // belongs to the class
}
Static methods:
class MyClass {
static void display() {
System.out.println("Static method");
}
}
MyClass.display(); // No need to create an object
Static blocks (used for static initialization):
===================================
Static blocks are recognized and executed at the time of loading the byte code to the memory.
class MyClass {
static {
System.out.println("Static block executed once when class is loaded");
}
}
Inside a static method or block, you cannot access non-static (instance) members directly because they require an instance of the class.
static methods:-
==============
Static methods are executed at the time of calling the method using the class name or reference variable of an object.
Can we override a static method?
No, you cannot override a static method in Java — but you can hide it. This is known as method hiding, not true overriding.

Why Not Overriding?
Static methods belong to the class, not the object.
Overriding works with instance methods that are resolved at runtime (polymorphism).
Static methods are resolved at compile-time using the reference type, not the actual object.
Example: Method Hiding
=====================
class Parent {
static void display() {
System.out.println("Parent static method");
}
}
class Child extends Parent {
static void display() {
System.out.println("Child static method");
}
}
Main Method:
public class Test {
public static void main(String[] args) {
Parent p = new Child();
p.display(); // Output: Parent static method ❗
}
}
Can we overload a static method?
Yes, you can overload a static method in Java.
Just like any other method, static methods can be overloaded based on different method signatures — meaning:
Different number of parameters
Different types of parameters
Different order of parameters (if types differ)

How to Work with Instance Members in Static Context?
You need to create an object:
static void myStaticMethod() {
MyClass obj = new MyClass();
System.out.println(obj.instanceVar);
}

final keyword in java:-
==================
The final keyword in Java is a non-access modifier used to indicate that something cannot be changed once it is assigned. It can be applied to:
Variables
Methods
Classes
1. Final Variables
===================
A final variable's value cannot be changed after it is assigned once.
final int x = 10;
x = 20;
You can declare a final variable without assigning it immediately, but you must assign it once before use — commonly in:
The constructor (for instance variables)
A static block (for static variables)

final int a; // allowed
a = 5; // assigned once
2. Final Methods
================
A method marked final cannot be overridden by subclasses.
class Parent {
final void show() {
System.out.println("Hello");
}
}
class Child extends Parent {
// void show() {} // Error: Cannot override final method
}
Use Case:
Prevent critical methods from being modified in subclasses
Ensure core logic stays intact
3. Final Classes
Meaning:
A final class cannot be extended (no subclassing allowed).
final class Utility {
// helper methods
}
Important Notes
=================
Use Case Restriction
final variable Cannot be reassigned
final method Cannot be overridden
final class Cannot be extended

Selenium automation testing course with Java-static and final keywords in java- class 13

Поделиться в:

Доступные форматы для скачивания:

Скачать видео mp4

  • Информация по загрузке:

Скачать аудио mp3

Похожие видео

Selenium automation testing course with Java-Encapsulation in Java- class 14

Selenium automation testing course with Java-Encapsulation in Java- class 14

Опции в Java — простое руководство

Опции в Java — простое руководство

Python NumPy module

Python NumPy module

Python Object Oriented Programming (OOP) - Full Course for Beginners

Python Object Oriented Programming (OOP) - Full Course for Beginners

Рабочая музыка для глубокой концентрации и сверхэффективности

Рабочая музыка для глубокой концентрации и сверхэффективности

Что делает программист весь день? Показываю

Что делает программист весь день? Показываю

Статические и нестатические переменные и методы в Java — простое полное руководство

Статические и нестатические переменные и методы в Java — простое полное руководство

Kubernetes — Простым Языком на Понятном Примере

Kubernetes — Простым Языком на Понятном Примере

Лямбда-выражения в Java — простое полное руководство

Лямбда-выражения в Java — простое полное руководство

Долбануть по Ирану, отжать Гренландию | Обычный вторник Трампа? (English subtitles)

Долбануть по Ирану, отжать Гренландию | Обычный вторник Трампа? (English subtitles)

Prawdziwy Powód, Dlaczego Psy CIĘ LIŻĄ (Szokujące!)

Prawdziwy Powód, Dlaczego Psy CIĘ LIŻĄ (Szokujące!)

Лучший Гайд по Kafka для Начинающих За 1 Час

Лучший Гайд по Kafka для Начинающих За 1 Час

Изучите Microsoft Active Directory (ADDS) за 30 минут

Изучите Microsoft Active Directory (ADDS) за 30 минут

Многопоточность в Java: объяснение за 10 минут

Многопоточность в Java: объяснение за 10 минут

Constructor Concept and This Keyword in Java

Constructor Concept and This Keyword in Java

Morning Coffee ☕❄️ Happy Music for Perfect Day ☀️ Relaxing Chillout House 2025 - 2026

Morning Coffee ☕❄️ Happy Music for Perfect Day ☀️ Relaxing Chillout House 2025 - 2026

Алгоритмическое mock-собеседование | Ex-Team Lead Яндекс

Алгоритмическое mock-собеседование | Ex-Team Lead Яндекс

Map и HashMap в Java — полное руководство

Map и HashMap в Java — полное руководство

Gra o Iran, z Polską w tle... - Komentarz Tygodnia Witold Gadowski

Gra o Iran, z Polską w tle... - Komentarz Tygodnia Witold Gadowski

ДАМПЫ В JAVA на практике, разбираем проблемы

ДАМПЫ В JAVA на практике, разбираем проблемы

© 2025 dtub. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: infodtube@gmail.com