java lecture note for bachelor students, Lecture notes of Computer Science

this documents are good java lecture notes

Typology: Lecture notes

2019/2020

Uploaded on 02/19/2023

muluken-kindachew
muluken-kindachew 🇪🇹

6 documents

1 / 28

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
POLYMORPHISM
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c

Partial preview of the text

Download java lecture note for bachelor students and more Lecture notes Computer Science in PDF only on Docsity!

POLYMORPHISM

polymorphism

  • (^) the ability to take more than one form
  • (^) particular operation may behave differently for different sub-classes of the same class
  • (^) the ability to refer to an object using either to actual form or a parent form
  • (^) enables us to “ program in the general ” rather than “ program in the specific .”

Cont. …

  • (^) rules of method overriding
    • (^) new method definition must have the same method signature
    • (^) If a method can't be inherited , you can’t override it
    • (^) Final and static method can’t overridden

Cont. …

  • (^) Example
    • (^) The passing average grade for students is 2. and above. However, for CE students the passing grade is 2.5 and above. if we have a class for CE students, the class is slightly different from the Student class. Hence, we can inherit the Student class to CE class, but we have to override some methods of the Student class

Ce.java

  • (^) …

Test.java

  • (^) …

Polymorphism using Overloading methods

  • (^) Overloading
    • (^) reuse the same method name in a class or subclass
    • (^) Different argument (number/type)
    • (^) Different return type [optional]

Example

  • (^) …

Final keyword

  • (^) Final class
    • (^) can't be sub classed
    • (^) can't ever be improved by another programmer
    • (^) none of the methods in that class will ever be overridden
    • (^) Provide absolute guarantee ( security )

Cont. …

  • (^) Final method
    • (^) Can’t overridden in the subclass
    • (^) Provide safety and security
    • (^) Class can contain non final method
    • (^) You can subclass a class contain final method

Abstract keyword

  • (^) Abstract class
    • (^) cannot be instantiated and must be extended
    • (^) used only as super classes
    • (^) Are incomplete
    • (^) may contain abstract methods

Cont. …

  • (^) Example :
    • (^) public abstract class MemberOfBiT {}
    • (^) public class Student extends MemberOfBiT { // must be extendes }
    • (^) MemberOfBiT me = new MemberOfBiT(); // cannot be instantiated

Cont. …

  • (^) Example

Cont. …

  • (^) A class that contains any abstract methods must be declared as an abstract class even if that class contains some concrete (non abstract) methods.
  • (^) Each concrete subclass of an abstract superclass also must provide concrete implementations of each of the superclass’s abstract methods