0% found this document useful (0 votes)
6 views

Mca I Yr. (Aiml) - Sem - I: Course Name: Object Oriented Programming

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Mca I Yr. (Aiml) - Sem - I: Course Name: Object Oriented Programming

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

MCA I Yr.

(AIML)- SEM – I

Course Name: Object Oriented Programming

Dr. Sachin Upadhye


Department of Computer Science and Applications
School of Computer Science and Engineering
RBU, Nagpur
[email protected], 9970094109
SYLLABUS OF SEMESTER - I,
MCA (MASTER OF COMPUTER APPLICATIONS)
(Artificial Intelligence and Machine Learning)

Course : Object Oriented Programming


Total Credits : 4
L: 3 Hrs, T: 0 Hr, P: 2 Hr, Per Week
Final and Super Keywords Inheritance
• Super is a keyword of Java which refers to the immediate parent
of a class and is used inside the subclass method definition for
calling a method defined in the superclass.

• A superclass having methods as private cannot be called. Only the


methods which are public and protected can be called by the
keyword super.

• It is also used by class constructors to invoke constructors of its


parent class.
Final and Super Keywords Inheritance
Uses of Super Class

•Super variables refer to the variable of a variable of the parent class.


•Super() invokes the constructor of immediate parent class.
•Super refers to the method of the parent class.
Final and Super Keywords Inheritance
s.
Final and Super Keywords Inheritance
s.
Final and Super Keywords Inheritance
What is final in Java?

Final is a keyword in Java that is used to restrict the user and can be
used in many respects. Final can be used with:
•Class
•Methods
•Variables
Final and Super Keywords Inheritance
Class is declared as final

When a class is declared as final, it cannot be extended further. Here


is an example what happens within a program
Final and Super Keywords Inheritance
method declared as final

A method declared as final cannot be overridden; this means even


when a child class can call the final method of parent class without
any issues, but the overriding will not be possible.

Here is a sample program showing what is not valid within a Java


program when a method is declared as final.
Final and Super Keywords Inheritance
s.
Final and Super Keywords Inheritance
Variable declare as final

• Once a variable is assigned with the keyword final, it always


contains the same exact value.

• if a final variable holds a reference to an object then the state of


the object can be altered if programmers perform certain
operations on those objects, but the variable will always refer to
the same object.
Final and Super Keywords Inheritance
A final variable that is not initialized at the time of declaration is
known as a blank final variable.

If you are declaring a final variable in a constructor, then you must


initialize the blank final variable within the constructor of the class.
Otherwise, the program might show a compilation error.
Final and Super Keywords Inheritance
s.
Final and Super Keywords Inheritance
Using final with inheritance
• During inheritance, we must declare methods with the final
keyword for which we are required to follow the same
implementation throughout all the derived classes.
• Note that it is not necessary to declare final methods in the initial
stage of inheritance(base class always).
• We can declare a final method in any subclass for which we want
that if any other class extends this subclass, then it must follow
the same implementation of the method as in that subclass.
Final and Super Keywords Inheritance
Using final to Prevent Inheritance

When a class is declared as final then it cannot be subclassed i.e. no


other class can extend it.
Final and Super Keywords Inheritance
Using final to Prevent Overriding

You might also like