Sie sind auf Seite 1von 12

Java OOP (Object Oriented

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.

 Usage of java this keyword


1. this can be used to refer current class instance variable.
2. this can be used to invoke current class constructor.
3. this can be used to invoke toString method.
This keyword
 Example without this keyword :- Example with this keyword:-
Inheritance 
 Inheritance in java is a mechanism in which one object acquires all the properties and
behaviors of parent object.
 Inheritance represents the IS-A relationship, also known as parent-child relationship.
 The class which inherits the properties of other is known as subclass (derived class, child
class) and the class whose properties are inherited is known as superclass (base class,
parent class).
 Why use inheritance in java
o For Method Overriding (so runtime polymorphism can be achieved).
o For Code Reusability.
 Real Example
Inheritance 
Inheritance 
 Syntax of Java Inheritance

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 :

2- Multilevel Inheritance : 3- Hierarchical Inheritance :


Example for Single Inheritance
Example continue…

Das könnte Ihnen auch gefallen