Day 28 and 30: java in Dynamic binding and Enum...Basic of Programming

What is Dynamic binding? Dynamic binding, also known as late binding, in Java refers to the resolution of method calls during runtime, based on the actual object's type, rather than the reference type. Key aspects of dynamic binding in Java: Runtime Resolution: The method to be called is determined at runtime, not compile-time. Method Overriding: Dynamic binding is heavily reliant on method overriding, where a subclass provides its own implementation of a method inherited from a superclass. Polymorphism: It enables polymorphism, allowing a single method call to invoke different implementations based on the object's type. Object-Oriented Programming: Dynamic binding is a fundamental concept in object-oriented programming, enabling code reusability and flexibility. Examples: When a subclass overrides a method from a superclass, the overridden method in the subclass is called at runtime based on the actual object type. Virtual Methods: In Java, methods are virtual by default, meaning they are bound at runtime based on the object's type. Contrast with Static Binding: Static binding, or early binding, resolves method calls at compile time based on the reference type. Abstract Classes Can have at least one abstract method? True Abstract classes SHOULD have at least one abstract method? False. Enum Enumeration Enum is a group of named constant objects Enum is our owned datatypes create the own reference by default, enum constant is public static and final. Enum constructors will be executed automatically at the time of enum loading. constant values will be created at the time of class loading EXAMPLE 1 enum players public enum players { DHONI, KOHLI, BUMRAH } EXAMPLE 2 What is an enum in Java? An enum is a special "class" that represents a group of constants (unchangeable variables, like final variables). Why is enum used? It is mainly used to define our own (pre-defined) data type. where can we create enum? inside class as well as outside class How to call enum in Java? You call a Java enum method via a reference to one of the constant values [] square bracket called group BASICS OF PROGRAMMING:- Java programming involves writing code using the Java language to instruct a computer to perform specific tasks programming Rules: 1) Don't say i don't know 2) Always say - Let me try. 3) Don't think about entire output. 4) Think about very next step. 5) Known to unknown 6) write down the known steps. 7) Think about variable. Add it if necessary. 8) Micro to macro. some topics to understand programming are datatypes, variables, = assignment operator method, method calling, arguments, return values

Apr 21, 2025 - 04:27
 0
Day 28 and 30: java in Dynamic binding and Enum...Basic of Programming

What is Dynamic binding?
Dynamic binding, also known as late binding, in Java refers to the resolution of method calls during runtime, based on the actual object's type, rather than the reference type.

Key aspects of dynamic binding in Java:
Runtime Resolution:
The method to be called is determined at runtime, not compile-time.

Method Overriding:

Dynamic binding is heavily reliant on method overriding, where a subclass provides its own implementation of a method inherited from a superclass.

Polymorphism:

It enables polymorphism, allowing a single method call to invoke different implementations based on the object's type.

Object-Oriented Programming:

Dynamic binding is a fundamental concept in object-oriented programming, enabling code reusability and flexibility.
Examples:
When a subclass overrides a method from a superclass, the overridden method in the subclass is called at runtime based on the actual object type.

Virtual Methods:

In Java, methods are virtual by default, meaning they are bound at runtime based on the object's type.

Contrast with Static Binding:

Static binding, or early binding, resolves method calls at compile time based on the reference type.

Abstract Classes Can have at least one abstract method? True

Abstract classes SHOULD have at least one abstract method? False.

Enum Enumeration

  1. Enum is a group of named constant objects
  2. Enum is our owned datatypes create the own reference
  3. by default, enum constant is public static and final.
  4. Enum constructors will be executed automatically at the time of enum loading.
  5. constant values will be created at the time of class loading

EXAMPLE 1

enum players

    public enum players
    {
    DHONI, KOHLI, BUMRAH
    } 

EXAMPLE 2

Image description

What is an enum in Java?

An enum is a special "class" that represents a group of constants (unchangeable variables, like final variables).

Why is enum used?
It is mainly used to define our own (pre-defined) data type.

where can we create enum?
inside class as well as outside class

How to call enum in Java?
You call a Java enum method via a reference to one of the constant values

[] square bracket called group

BASICS OF PROGRAMMING:-

Java programming involves writing code using the Java language to instruct a computer to perform specific tasks

programming Rules:

1) Don't say i don't know
2) Always say - Let me try.
3) Don't think about entire output.
4) Think about very next step.
5) Known to unknown
6) write down the known steps.
7) Think about variable. Add it if necessary.
8) Micro to macro.

some topics to understand programming are

datatypes, variables, = assignment operator
method, method calling, arguments, return values