Java OOP (Object Oriented Programming) : Programming Department Fifth Stage 2017-2018
Java OOP (Object Oriented Programming) : Programming Department Fifth Stage 2017-2018
Programming)
Programming Department
Fifth stage
2017-2018
Lectured by : Baxan.A.Mahmood
Static Keyword
The static keyword in java is used for memory management mainly. We can apply java
static keyword with variables, methods, blocks and nested class. The static keyword belongs
to the class than instance of the class.
The static can be:
• Variable (also known as class variable)
• Method (also known as class method)
Advantage of static variable
• It makes your program memory efficient (i.e it saves memory).
Static variable Syntax
static data_type variable_name;
Static keyword
Example without static keyword :- Example with static keyword:-
This keyword
This is a keyword in Java. It can be used inside the Method or constructor of Class.
It(this) works as a reference to the current Object whose Method or constructor is being
invoked.
The this keyword can be used to refer to any member of the current object from within an
instance Method or a constructor.
class Subclass-name extends Superclass-name
{
//methods and fields
}
extends Keyword:-
- extends is the keyword used to inherit the properties of a class. Following is the syntax of
extends keyword
class Super { ..... ..... }
class Sub extends Super
{ ..... ..... }
Inheritance
Super Class: The class whose features are inherited is known as super class(or a base class
or a parent class).
Sub Class: The class that inherits the other class
is known as sub class.
The subclass can add its own fields and methods
in addition to the superclass fields and methods.
Inheritance
Types of Inheritance in Java:-
1. Single Inheritance :