SlideShare a Scribd company logo
Ahmed - 1 . Inheritance
Polash - 2 . Polymorphism
Aman - 3 . Overloading
- 4 . Overriding
Mustafiz - 5 . Construction
- 6 . Encapsulation
Galib - 7 . Diff between method n construction
- 8 . Abstract
Welcome to our presentation
INTRODUCTION TO INHERITANCE
• Java classes are used in several ways.This is basically
by creating new classes,resuing the properties
existing one.
• The deriving the new class from an old one is called
inheritance .
• The old class is known as base class or super class.
• The class who inherit the properties of the base class
is called derived class or sub class.
TYPES OF INHERITANCE
• Single inheritance(one super class)
• Multiple inheritance
• Multilevel inheritance
• Hierarchical inheritance
DEFINE SUBCLASS
• Class sub-classname extends super-classname
• {
• variable declaration ;// sub class variables
• method declaration ;// sub class method
• }
• The keyword extends signifies that the properties of
the super class are extended to the sub class.
EXAMPLE OF SINGLE INHERITANCE
• Class sum //Super class
• {
• int a=10;
• int b=20;
• void show()
• {
• System.out.println(“value of a :-” +a);
• System.out.println(“value of a :-” +b);
• }
• }
• Class sum2 extends sum //base class
• {
• public static void main(String args[])
• {
• Sum2 obj =new sum2();
• Obj.show1();
}
}
Polymorphism is the ability of an object to
take on many forms. The most common use
of polymorphism in OOP occurs when a
parent class reference is used to refer to a
child class object. Any Java object that can
pass more than one IS-A test is considered
to be polymorphic. Any Java object that can
pass more than one IS-A test is considered
to be polymorphic. In Java, all Java objects
are polymorphic since any object will pass
the IS-A test for their own type and for the
class Object.
Polymorphism
Public class Dog extends Animal {
Public void make sound () {
System.out.println(“Woof !”);
}
Public void make sound (Boolean
injured) {
If (injured){
System.out.println(“Whimper”);
}
}
Polymorphism sample code
Definition: Overloading occurs when two or more
methods in one class have the same
method name but different parameters.
Overloading
Java
Java
Definition:
Overriding means having two methods with the same
method name and parameters. One of the methods is in
the parent class and the other is in the child class.
Overriding allows a child class to provide a specific
implementation of a method that is already provided its
parent class.
Java
Java
 In the example above, the dog variable is declared
to be a Dog. During compile time, the compiler
checks if the Dog class has the bark() method. As
long as the Dog class has the bark() method, the
code compilers. At run-time, a Hound is created
and assigned to dog. The JVM knows that dog is
referring to the object of Hound, so it calls
the bark() method of Hound. This is called
Dynamic Polymorphism
Constructor
A constructor in Java is a block of code similar to a method
that’s called when an instance of an object is created .
Constructor are 2 type
1 . Default constructor (no-arg
constructor)
2 . Parameterized constructor
Default Parameterized
Student obj = new Student ( ) Student obj = new Student ( name )
Difference between default and parameterized constructor
Public class StudentResult {
private string Full_Name ;
private string Exam_Name ;
private string Exam_Grade ;
StudentResult( String name , String grade ) {
Full_Name = name ;
Exam_Grade = grade ;
}
Constructor Sample Code
Encapsulation is one of the four fundamental OOP
concepts. The other three are inheritance,
polymorphism, and abstraction. Encapsulation in Java is
a mechanism of wrapping the data (variables) and code
acting on the data (methods) together as a single unit. ...
Declare the variables of a class as private.
To achieve encapsulation in Java −
1 . Declare the variables of a class as private.
2 . Provide public setter and getter methods
to modify and view the variables values.
Encapsulation
public class EncapTest {
private String name;
private String idNum;
public String getName() {
return name;
}
public String getIdNum() {
return idNum;
}
public void setName(String newName) {
name = newName;
}
public void setIdNum( String newId) {
idNum = newId;
}
}
Encapsulation Sample code
Method Constructor
1. Method expose the object
behavior.
1. Constructor initialize the state of
an object.
2. Method name may or may not be
same as the class name.
2. Constructor name must be same
as the class name.
3. . Method must have return
type ..
3. Constructor must not have return
type.
4. Method is invoked explicity . 4. Constructor is invoked implicity .
5. Compiler don’t provide method
any case.
5. Compiler provides a default
constructor if there's no constructor .
Difference Between Method and Constructor
Student
- Id : String
- name : String
- mark : String
+ student()
+ student(string:id)
Student
- Id : String
- name : String
- mark : String
+ student() : void
UML Diagram between Constructor and Method
Abstract
Abstract : when we don’t create an object
then it is called abstract .
1 . We use it before the concrete class .
2 . It has its own method .
3 . Abstract doesn’t have any body .
4 . Abstract classes cannot be instantiated, but
they can be subclassed.
5 . When an abstract class is subclassed, the
subclass usually provides implementations for all
of the abstract methods in its parent class.
Abstract class HelloAbstractWorld { }
Class AbstractDemo {
Public static void main (String ar [ ]) {
System.out.println(“Hello World”);
//HelloAbstractWorld obj = new HelloAbstractWorld
}
} /* HelloAbstractWorld is Abstract and cannot be
intantiated */
Simple Abstract Code
Thank you
Hope u don’t get bored !!

More Related Content

What's hot (20)

PDF
java-06inheritance
Arjun Shanka
 
PPT
Inheritance and Polymorphism
BG Java EE Course
 
PPTX
Ppt on this and super keyword
tanu_jaswal
 
PPT
Java lec class, objects and constructors
Jan Niño Acierto
 
PDF
Python Class | Python Programming | Python Tutorial | Edureka
Edureka!
 
PDF
javainheritance
Arjun Shanka
 
PPTX
Multiple inheritance possible in Java
Kurapati Vishwak
 
PPTX
Java class,object,method introduction
Sohanur63
 
PPTX
Chapter 07 inheritance
Praveen M Jigajinni
 
PPT
Oops in Java
malathip12
 
PPT
Java Programming - Inheritance
Oum Saokosal
 
PPTX
Inner classes in java
PhD Research Scholar
 
PPTX
Object Oriented Programming with C#
foreverredpb
 
PPT
Java: Inheritance
Tareq Hasan
 
PPT
Unit 3 Java
arnold 7490
 
PPTX
Classes, objects in JAVA
Abhilash Nair
 
PPTX
Oop in kotlin
Abdul Rahman Masri Attal
 
PPTX
Dynamic method dispatch
yugandhar vadlamudi
 
PPTX
OOPS in Java
Zeeshan Khan
 
java-06inheritance
Arjun Shanka
 
Inheritance and Polymorphism
BG Java EE Course
 
Ppt on this and super keyword
tanu_jaswal
 
Java lec class, objects and constructors
Jan Niño Acierto
 
Python Class | Python Programming | Python Tutorial | Edureka
Edureka!
 
javainheritance
Arjun Shanka
 
Multiple inheritance possible in Java
Kurapati Vishwak
 
Java class,object,method introduction
Sohanur63
 
Chapter 07 inheritance
Praveen M Jigajinni
 
Oops in Java
malathip12
 
Java Programming - Inheritance
Oum Saokosal
 
Inner classes in java
PhD Research Scholar
 
Object Oriented Programming with C#
foreverredpb
 
Java: Inheritance
Tareq Hasan
 
Unit 3 Java
arnold 7490
 
Classes, objects in JAVA
Abhilash Nair
 
Dynamic method dispatch
yugandhar vadlamudi
 
OOPS in Java
Zeeshan Khan
 

Similar to Java (20)

PPTX
Java chapter 5
Abdii Rashid
 
PPTX
Detailed_description_on_java_ppt_final.pptx
technicaljd3
 
PDF
OOPs Concepts - Android Programming
Purvik Rana
 
PPTX
Unit No 3 Inheritance annd Polymorphism.pptx
DrYogeshDeshmukh1
 
PPTX
AkhileshD_Presentation_Core_Java_OOPs.pptx
Akhilesh740777
 
PPSX
Oop features java presentationshow
ilias ahmed
 
PPTX
UNIT 5.pptx
CurativeServiceDivis
 
PPTX
Introduction to OOPs second year cse.pptx
solemanhldr
 
PDF
‏‏‏‏‏‏oop lecture objectives will come.pdf
nabeehmohammedtaher
 
PPT
InheritanceAndPolymorphismprein Java.ppt
gayatridwahane
 
PPT
06 InheritanceAndPolymorphism.ppt
ParikhitGhosh1
 
PPT
Inheritance & Polymorphism - 2
PRN USM
 
PDF
Java Programming - 04 object oriented in java
Danairat Thanabodithammachari
 
PDF
Object oriented programming inheritance
Renas Rekany
 
PPTX
Core java oop
Parth Shah
 
PDF
Java Inheritance
Rosie Jane Enomar
 
PPT
Java for the Impatient, Java Constructors, Scope, Wrappers, Inheritance, and ...
argsstring
 
PPTX
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
VinishA23
 
DOC
Abstract
snehajyothi
 
DOCX
JAVA Notes - All major concepts covered with examples
Sunil Kumar Gunasekaran
 
Java chapter 5
Abdii Rashid
 
Detailed_description_on_java_ppt_final.pptx
technicaljd3
 
OOPs Concepts - Android Programming
Purvik Rana
 
Unit No 3 Inheritance annd Polymorphism.pptx
DrYogeshDeshmukh1
 
AkhileshD_Presentation_Core_Java_OOPs.pptx
Akhilesh740777
 
Oop features java presentationshow
ilias ahmed
 
Introduction to OOPs second year cse.pptx
solemanhldr
 
‏‏‏‏‏‏oop lecture objectives will come.pdf
nabeehmohammedtaher
 
InheritanceAndPolymorphismprein Java.ppt
gayatridwahane
 
06 InheritanceAndPolymorphism.ppt
ParikhitGhosh1
 
Inheritance & Polymorphism - 2
PRN USM
 
Java Programming - 04 object oriented in java
Danairat Thanabodithammachari
 
Object oriented programming inheritance
Renas Rekany
 
Core java oop
Parth Shah
 
Java Inheritance
Rosie Jane Enomar
 
Java for the Impatient, Java Constructors, Scope, Wrappers, Inheritance, and ...
argsstring
 
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
VinishA23
 
Abstract
snehajyothi
 
JAVA Notes - All major concepts covered with examples
Sunil Kumar Gunasekaran
 
Ad

Recently uploaded (20)

PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
Dimensions of Societal Planning in Commonism
StefanMz
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Ad

Java

  • 1. Ahmed - 1 . Inheritance Polash - 2 . Polymorphism Aman - 3 . Overloading - 4 . Overriding Mustafiz - 5 . Construction - 6 . Encapsulation Galib - 7 . Diff between method n construction - 8 . Abstract Welcome to our presentation
  • 2. INTRODUCTION TO INHERITANCE • Java classes are used in several ways.This is basically by creating new classes,resuing the properties existing one. • The deriving the new class from an old one is called inheritance . • The old class is known as base class or super class. • The class who inherit the properties of the base class is called derived class or sub class.
  • 3. TYPES OF INHERITANCE • Single inheritance(one super class) • Multiple inheritance • Multilevel inheritance • Hierarchical inheritance
  • 4. DEFINE SUBCLASS • Class sub-classname extends super-classname • { • variable declaration ;// sub class variables • method declaration ;// sub class method • } • The keyword extends signifies that the properties of the super class are extended to the sub class.
  • 5. EXAMPLE OF SINGLE INHERITANCE • Class sum //Super class • { • int a=10; • int b=20; • void show() • { • System.out.println(“value of a :-” +a); • System.out.println(“value of a :-” +b); • } • } • Class sum2 extends sum //base class • { • public static void main(String args[]) • { • Sum2 obj =new sum2(); • Obj.show1(); } }
  • 6. Polymorphism is the ability of an object to take on many forms. The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object. Any Java object that can pass more than one IS-A test is considered to be polymorphic. Any Java object that can pass more than one IS-A test is considered to be polymorphic. In Java, all Java objects are polymorphic since any object will pass the IS-A test for their own type and for the class Object. Polymorphism
  • 7. Public class Dog extends Animal { Public void make sound () { System.out.println(“Woof !”); } Public void make sound (Boolean injured) { If (injured){ System.out.println(“Whimper”); } } Polymorphism sample code
  • 8. Definition: Overloading occurs when two or more methods in one class have the same method name but different parameters. Overloading
  • 11. Definition: Overriding means having two methods with the same method name and parameters. One of the methods is in the parent class and the other is in the child class. Overriding allows a child class to provide a specific implementation of a method that is already provided its parent class.
  • 14.  In the example above, the dog variable is declared to be a Dog. During compile time, the compiler checks if the Dog class has the bark() method. As long as the Dog class has the bark() method, the code compilers. At run-time, a Hound is created and assigned to dog. The JVM knows that dog is referring to the object of Hound, so it calls the bark() method of Hound. This is called Dynamic Polymorphism
  • 15. Constructor A constructor in Java is a block of code similar to a method that’s called when an instance of an object is created . Constructor are 2 type 1 . Default constructor (no-arg constructor) 2 . Parameterized constructor Default Parameterized Student obj = new Student ( ) Student obj = new Student ( name ) Difference between default and parameterized constructor
  • 16. Public class StudentResult { private string Full_Name ; private string Exam_Name ; private string Exam_Grade ; StudentResult( String name , String grade ) { Full_Name = name ; Exam_Grade = grade ; } Constructor Sample Code
  • 17. Encapsulation is one of the four fundamental OOP concepts. The other three are inheritance, polymorphism, and abstraction. Encapsulation in Java is a mechanism of wrapping the data (variables) and code acting on the data (methods) together as a single unit. ... Declare the variables of a class as private. To achieve encapsulation in Java − 1 . Declare the variables of a class as private. 2 . Provide public setter and getter methods to modify and view the variables values. Encapsulation
  • 18. public class EncapTest { private String name; private String idNum; public String getName() { return name; } public String getIdNum() { return idNum; } public void setName(String newName) { name = newName; } public void setIdNum( String newId) { idNum = newId; } } Encapsulation Sample code
  • 19. Method Constructor 1. Method expose the object behavior. 1. Constructor initialize the state of an object. 2. Method name may or may not be same as the class name. 2. Constructor name must be same as the class name. 3. . Method must have return type .. 3. Constructor must not have return type. 4. Method is invoked explicity . 4. Constructor is invoked implicity . 5. Compiler don’t provide method any case. 5. Compiler provides a default constructor if there's no constructor . Difference Between Method and Constructor
  • 20. Student - Id : String - name : String - mark : String + student() + student(string:id) Student - Id : String - name : String - mark : String + student() : void UML Diagram between Constructor and Method
  • 21. Abstract Abstract : when we don’t create an object then it is called abstract . 1 . We use it before the concrete class . 2 . It has its own method . 3 . Abstract doesn’t have any body . 4 . Abstract classes cannot be instantiated, but they can be subclassed. 5 . When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class.
  • 22. Abstract class HelloAbstractWorld { } Class AbstractDemo { Public static void main (String ar [ ]) { System.out.println(“Hello World”); //HelloAbstractWorld obj = new HelloAbstractWorld } } /* HelloAbstractWorld is Abstract and cannot be intantiated */ Simple Abstract Code
  • 23. Thank you Hope u don’t get bored !!