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

PPTX
Java(Polymorphism)
PPTX
encapsulation, inheritance, overriding, overloading
PPTX
oops concept in java | object oriented programming in java
PDF
CLASS & OBJECT IN JAVA
PPTX
Inheritance in Java
PPT
PDF
Classes and objects in java
PPTX
Java Inheritance - sub class constructors - Method overriding
Java(Polymorphism)
encapsulation, inheritance, overriding, overloading
oops concept in java | object oriented programming in java
CLASS & OBJECT IN JAVA
Inheritance in Java
Classes and objects in java
Java Inheritance - sub class constructors - Method overriding

What's hot (20)

PDF
java-06inheritance
PPT
Inheritance and Polymorphism
PPTX
Ppt on this and super keyword
PPT
Java lec class, objects and constructors
PDF
Python Class | Python Programming | Python Tutorial | Edureka
PDF
javainheritance
PPTX
Multiple inheritance possible in Java
PPTX
Java class,object,method introduction
PPTX
Chapter 07 inheritance
PPT
Oops in Java
PPT
Java Programming - Inheritance
PPTX
Inner classes in java
PPTX
Object Oriented Programming with C#
PPT
Java: Inheritance
PPT
Unit 3 Java
PPTX
Classes, objects in JAVA
PPTX
PPTX
Dynamic method dispatch
PPTX
OOPS in Java
java-06inheritance
Inheritance and Polymorphism
Ppt on this and super keyword
Java lec class, objects and constructors
Python Class | Python Programming | Python Tutorial | Edureka
javainheritance
Multiple inheritance possible in Java
Java class,object,method introduction
Chapter 07 inheritance
Oops in Java
Java Programming - Inheritance
Inner classes in java
Object Oriented Programming with C#
Java: Inheritance
Unit 3 Java
Classes, objects in JAVA
Dynamic method dispatch
OOPS in Java
Ad

Similar to Java (20)

PPTX
Java chapter 5
PPTX
Detailed_description_on_java_ppt_final.pptx
PDF
OOPs Concepts - Android Programming
PPTX
Unit No 3 Inheritance annd Polymorphism.pptx
PPTX
AkhileshD_Presentation_Core_Java_OOPs.pptx
PPSX
Oop features java presentationshow
PPTX
PPTX
Introduction to OOPs second year cse.pptx
PDF
‏‏‏‏‏‏oop lecture objectives will come.pdf
PPT
InheritanceAndPolymorphismprein Java.ppt
PPT
06 InheritanceAndPolymorphism.ppt
PPT
Inheritance & Polymorphism - 2
PDF
Java Programming - 04 object oriented in java
PDF
Object oriented programming inheritance
PPTX
Core java oop
PDF
Java Inheritance
PPT
Java for the Impatient, Java Constructors, Scope, Wrappers, Inheritance, and ...
PPTX
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
DOC
Abstract
PPTX
OBJECT ORIENTED PROGRAMMING STRUCU2.pptx
Java chapter 5
Detailed_description_on_java_ppt_final.pptx
OOPs Concepts - Android Programming
Unit No 3 Inheritance annd Polymorphism.pptx
AkhileshD_Presentation_Core_Java_OOPs.pptx
Oop features java presentationshow
Introduction to OOPs second year cse.pptx
‏‏‏‏‏‏oop lecture objectives will come.pdf
InheritanceAndPolymorphismprein Java.ppt
06 InheritanceAndPolymorphism.ppt
Inheritance & Polymorphism - 2
Java Programming - 04 object oriented in java
Object oriented programming inheritance
Core java oop
Java Inheritance
Java for the Impatient, Java Constructors, Scope, Wrappers, Inheritance, and ...
ITT 202 PRINCIPLES OF OBJECT ORIENTED TECHNIQUE
Abstract
OBJECT ORIENTED PROGRAMMING STRUCU2.pptx
Ad

Recently uploaded (20)

PDF
Electrolyte Disturbances and Fluid Management A clinical and physiological ap...
PPTX
Odoo 18 Sales_ Managing Quotation Validity
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PPTX
IMMUNIZATION PROGRAMME pptx
PPTX
How to Manage Global Discount in Odoo 18 POS
PDF
Sunset Boulevard Student Revision Booklet
PDF
High Ground Student Revision Booklet Preview
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
PDF
English Language Teaching from Post-.pdf
PDF
Landforms and landscapes data surprise preview
PPTX
Strengthening open access through collaboration: building connections with OP...
PDF
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
PDF
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
PDF
What Is Coercive Control? Understanding and Recognizing Hidden Abuse
PPTX
How to Manage Loyalty Points in Odoo 18 Sales
PDF
LDMMIA Reiki Yoga Workshop 15 MidTerm Review
PPTX
vedic maths in python:unleasing ancient wisdom with modern code
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
LDMMIA Reiki Yoga S2 L3 Vod Sample Preview
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
Electrolyte Disturbances and Fluid Management A clinical and physiological ap...
Odoo 18 Sales_ Managing Quotation Validity
Cardiovascular Pharmacology for pharmacy students.pptx
IMMUNIZATION PROGRAMME pptx
How to Manage Global Discount in Odoo 18 POS
Sunset Boulevard Student Revision Booklet
High Ground Student Revision Booklet Preview
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
English Language Teaching from Post-.pdf
Landforms and landscapes data surprise preview
Strengthening open access through collaboration: building connections with OP...
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
What Is Coercive Control? Understanding and Recognizing Hidden Abuse
How to Manage Loyalty Points in Odoo 18 Sales
LDMMIA Reiki Yoga Workshop 15 MidTerm Review
vedic maths in python:unleasing ancient wisdom with modern code
Week 4 Term 3 Study Techniques revisited.pptx
LDMMIA Reiki Yoga S2 L3 Vod Sample Preview
NOI Hackathon - Summer Edition - GreenThumber.pptx

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 !!