'Back-End/Java_1'에 해당되는 글 48건

donaricano-btn

Static Binding and Dynamic Binding


1. Binding

- Connecting a method call to the method body is known ad binding


1) static binding(early binding)

2) dynamic binding(late binding)


2. Static binding

- When type of the object is determined at compiled time, is is known as static binding

- If there is any private, final or static method in class, there is static binding



3. Dynamic binding

- When type of the object is determined at run-time, it is known as dynamic binding

 

- Object type can't be determinded by the compiler, because the instance of Dog is also an instance of Animal, so Compiler doesn't know its type


'Back-End > Java_1' 카테고리의 다른 글

[Java] Abstract class  (0) 2016.09.12
[Java] Instanceof  (0) 2016.09.09
[Java] Runtime Polymorphism  (0) 2016.09.08
[Java] Final keyword  (0) 2016.09.07
[Java] Instance initializer block  (0) 2016.09.07
블로그 이미지

리딩리드

,
donaricano-btn

 Runtime Polymorphism


1. Polymorphism

1) compile time polymorphism

- You overload static method in java

2) runtime polymorphism


2. Runtime Polymorphism(Dynamic Method Dispatch)

- Process in which a call to an overridden method is resolved at runtime rather than compile-time

- an overridden method is called through the reference variable of a superclass


3. Upcasting

- When reference variable of Parent class refers to the object of Child class, It is known as upcasting



4. Runtime Polymorphism example

 

- 8,9


5. Runtime Polymorphism with data member

- Runtime polymorphism can't be achieved by data members

 

- 0 

'Back-End > Java_1' 카테고리의 다른 글

[Java] Instanceof  (0) 2016.09.09
[Java] Static Binding and Dynamic Binding  (0) 2016.09.08
[Java] Final keyword  (0) 2016.09.07
[Java] Instance initializer block  (0) 2016.09.07
[Java] Super keyword  (0) 2016.08.25
블로그 이미지

리딩리드

,
donaricano-btn

 Final keyword

- It in java is used to restrict the user

- Stop Value Change

- Stop Method Overridding

- Stop Inheritance


1. How to use

- final keyword can be applied with the variables, a final variable that have no value it is called blank final variable or uninitialized final variable

- blank final variable

a. It can be initialized in the constructor only

b. It can be static also which will be initialized in the static block only


2. Final variable


Complile time error

Final variable once assigned a value can never be changed


3. Final method

 

Complile time error

- It cannot override it


4. Final class

 

Complile time error

- You cannot extend it


5. Question

1) Is final method inherited?

- final method is inherited but you cannot override

2) What is blank or uninitialized final variable?

- A final variable that is not initialized at the time of declaration is known as blank final variable

- It can be initialized only in constructor

 

3) static blank final variable

- A static final variable that is not initialized at the time of declaration is known as static blank final variable

- It can be initialized only in static block

 

4) What is final parameter?

- You cannot change the value of final it

 

Complile time error

5) Can we declare a constructor final?

- No, because is never inherited



'Back-End > Java_1' 카테고리의 다른 글

[Java] Static Binding and Dynamic Binding  (0) 2016.09.08
[Java] Runtime Polymorphism  (0) 2016.09.08
[Java] Instance initializer block  (0) 2016.09.07
[Java] Super keyword  (0) 2016.08.25
[Java] Covariant Return type  (0) 2016.08.24
블로그 이미지

리딩리드

,
donaricano-btn

 Instance initializer block


- It used to initialize the instance data member

- It run each time when object of the class is created

- The initialization of the instance variable can be directly but there can be performed extra operations while initializing the instance variable it the instance initializer block


1. Why use instance initializer block?

- Suppose I have to perform some operations while assigning value to instance data member


2. Example


3. What is invoked first, instance initializer block or constructor?

1) How to work

- It seems that instance initializer block is firstly invoked but NO

- The java compiler copies the instance initializer block in the constructor after the first statement super()

- constructor is invoked firstly

4. Rules for instance initiallizer block

1) The instance initializer block is created when instance of the class is created

2) It is invoked after the parent class constructor is invoked

3) It comes in the order in which they appear


'Back-End > Java_1' 카테고리의 다른 글

[Java] Runtime Polymorphism  (0) 2016.09.08
[Java] Final keyword  (0) 2016.09.07
[Java] Super keyword  (0) 2016.08.25
[Java] Covariant Return type  (0) 2016.08.24
[Java] Overloading vs Overriding  (0) 2016.08.24
블로그 이미지

리딩리드

,