SlideShare a Scribd company logo
1 of 23
Welcome To
Our
presentation
PRESENTATION TOPICS IS
InheritanceandPolymorphism
InJava
OURGROUPNAMEIS
Malware
Submitted By:
1. S.M.Zahidul Islam 152-15-5925
2. Jakir Hasan 152-15-5617
3. Saniatul Haque 152-15- 5545
4. Akteruzzaman 152-15-5671
Submitted To:
Md. Zahid Hasan
senior lecturer
Dept. of CSE
Daffodil International University
What is inheritance?
Inheritance is a fundamental Object Oriented
concept
A class can be defined as a "subclass" of another
class.
The subclass inherits all data attributes of its
superclass
The subclass inherits all methods of its
superclass
The subclass can:
Add new functionality
Use inherited functionality
Override inherited functionality
Benefit of using inheritance
 A code can be used again and again
 Inheritance in Java enhances the properties of the
class, which means that property of the parent class
will automatically be inherited by the base class
 It can define more specialized classes by adding
new details.
keyword
 Keyword:
 Inheritance is declared using the "extends" keyword
 To access Super Class from Sub Class we use super keyword
EXAMPLE
public class SuperClass {
Scanner sc = new Scanner(System.in); // Here we take input from
Keyboard
public double CircleArea(){
double pi=3.1416,num1=0,r=0,CircleAreaResult=0;
num1=sc.nextDouble(); // num1 input taken
r=sc.nextDouble(); // r input taken
CircleAreaResult = pi*num1*(r*r);
return CircleAreaResult;
}
public double TriangleArea(){
double base,hight,TriangleAreaResult = 0;
base=sc.nextDouble(); // Here base input taken keyboard
hight=sc.nextDouble(); // hight input taken from keyborad
TriangleAreaResult = 0.5*base*hight;
return TriangleAreaResult;
}
EXAMPLE(continue)
public void Result() {
double Result1,Result2;
Result1= CircleArea();
Result2= TriangleArea();
System.out.println(“Circle Area : “+Result1+”nTriangle Area :
“+Result2);
}
}
public class Main extends SuperClass{
public static void main(String[] args) {
SuperClass sp= new SuperClass();
sp.Result();
}
}
Access Modifiers
 Private data fields are not accessible to derived classes
 Protected visibility allows data fields to be accessed either by the class
defining it or any subclass.
 In general, it is better to use private visibility because
subclasses may be written by different programmers and
it is always good practice to restrict and control access to
the superclass data fields
 Members (variables and methods) declared with public
visibility are accessible, and those with private visibility
are not.
Polymorphism
 Polymorphism come from the two Greek words
‘poly’ meaning many and ‘morphs” meaning forms.
The ability to exist in different form is called
polymorphism. The same variable or method can
perform different tasks; the programmer has the
advantage of writing flexible code.
Method Overloading
 When 2 or more methods in a class have the same method names with
different arguments, it is said to be method overloading.
 Overloading does not block inheritance from the superclass.
 Overloaded methods must have different method
signatures.
Example
Method Overriding
 When a method in a class has the same method name with same
arguments as that of the superclass, it is said to be method overriding.
 Overriding blocks inheritance from the superclass.
 Overridden methods must have same signature.
EXAMPLE
Abstruct class and method
 A class that is declared abstract
 Ex - abstract class Demo
 It may or may not use abstract
methods
 A method that is declared abstract
 A method that is declared without an
implementation
 Ex - abstract void add(int x, int y);
Example
public abstract class Shape {
//Abstract method i.e no implementation
abstract void Area();
}
public class Rectangle extends Shape {
@Override
void Area() {
Double area = length * width;
}
}
public class Circle extends Shape {
@Override
void Area() {
Double area = 3.14 * radius*radius;
}
}
Interface
 Interfaces are declared using the interface keyword
 Interface can contain :
 method signature
(no implementation)
 constant declarations
(variable declarations that are declared
to be both static and final)
UML of interface
Example
interface MyInterface
{
public void method1();
public void method2();
}
class XYZ implements MyInterface
{
public void method1() { System.out.println("implementation of method1"); }
public void method2() { System.out.println("implementation of method2"); }
public static void main(String arg[]) {
MyInterface obj = new XYZ(); obj. method1();
}
}
Output:
implementation of method1
Difference Between Interface and Abstract Class
 Main difference is methods of a Java interface are implicitly abstract and
cannot have implementations. A Java abstract class can have instance
methods that implements a default behavior.
 Variables declared in a Java interface is by default final. An abstract class
may contain non-final variables.
 Java interface should be implemented using keyword “implements”; A Java
abstract class should be extended using keyword “extends”.
 An interface can extend another Java interface only, an abstract class can
extend another Java class and implement multiple Java interfaces.
 A Java class can implement multiple interfaces but it can extend only one
abstract class.
 Interface is absolutely abstract and cannot be instantiated; A Java abstract
class also cannot be instantiated, but can be invoked if a main() exists.
Thank
You
All

More Related Content

What's hot

Inheritance and Polymorphism in java simple and clear
Inheritance and Polymorphism in java simple and clear Inheritance and Polymorphism in java simple and clear
Inheritance and Polymorphism in java simple and clear ASHNA nadhm
 
Basic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentBasic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentSuresh Mohta
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritanceArjun Shanka
 
Polymorphism in java, method overloading and method overriding
Polymorphism in java,  method overloading and method overridingPolymorphism in java,  method overloading and method overriding
Polymorphism in java, method overloading and method overridingJavaTportal
 
8 abstract classes and interfaces
8   abstract classes and interfaces 8   abstract classes and interfaces
8 abstract classes and interfaces Tuan Ngo
 
Exception Handling in C#
Exception Handling in C#Exception Handling in C#
Exception Handling in C#Abid Kohistani
 
Access Modifiers in C# ,Inheritance and Encapsulation
Access Modifiers in C# ,Inheritance and EncapsulationAccess Modifiers in C# ,Inheritance and Encapsulation
Access Modifiers in C# ,Inheritance and EncapsulationAbid Kohistani
 
9781439035665 ppt ch10
9781439035665 ppt ch109781439035665 ppt ch10
9781439035665 ppt ch10Terry Yoast
 
Oops presentation java
Oops presentation javaOops presentation java
Oops presentation javaJayasankarPR2
 
Object Oriented Principles
Object Oriented PrinciplesObject Oriented Principles
Object Oriented PrinciplesSujit Majety
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentationtigerwarn
 

What's hot (19)

Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Lecture 18
Lecture 18Lecture 18
Lecture 18
 
Inheritance and Polymorphism in java simple and clear
Inheritance and Polymorphism in java simple and clear Inheritance and Polymorphism in java simple and clear
Inheritance and Polymorphism in java simple and clear
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Basic concept of class, method , command line-argument
Basic concept of class, method , command line-argumentBasic concept of class, method , command line-argument
Basic concept of class, method , command line-argument
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritance
 
Interface
InterfaceInterface
Interface
 
Polymorphism in java, method overloading and method overriding
Polymorphism in java,  method overloading and method overridingPolymorphism in java,  method overloading and method overriding
Polymorphism in java, method overloading and method overriding
 
8 abstract classes and interfaces
8   abstract classes and interfaces 8   abstract classes and interfaces
8 abstract classes and interfaces
 
Exception Handling in C#
Exception Handling in C#Exception Handling in C#
Exception Handling in C#
 
Access Modifiers in C# ,Inheritance and Encapsulation
Access Modifiers in C# ,Inheritance and EncapsulationAccess Modifiers in C# ,Inheritance and Encapsulation
Access Modifiers in C# ,Inheritance and Encapsulation
 
9781439035665 ppt ch10
9781439035665 ppt ch109781439035665 ppt ch10
9781439035665 ppt ch10
 
Chap11
Chap11Chap11
Chap11
 
Oops presentation java
Oops presentation javaOops presentation java
Oops presentation java
 
Object Oriented Principles
Object Oriented PrinciplesObject Oriented Principles
Object Oriented Principles
 
Javapolymorphism
JavapolymorphismJavapolymorphism
Javapolymorphism
 
Abstract Class Presentation
Abstract Class PresentationAbstract Class Presentation
Abstract Class Presentation
 
Inheritance in Java
Inheritance in JavaInheritance in Java
Inheritance in Java
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 

Similar to Java presentation

L7 inheritance
L7 inheritanceL7 inheritance
L7 inheritanceteach4uin
 
L7 inheritance
L7 inheritanceL7 inheritance
L7 inheritanceteach4uin
 
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptxSodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptxRudranilDas11
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Javabackdoor
 
Chap3 inheritance
Chap3 inheritanceChap3 inheritance
Chap3 inheritanceraksharao
 
Core java interview questions
Core java interview questionsCore java interview questions
Core java interview questionsVinay Kumar
 
Application package
Application packageApplication package
Application packageJAYAARC
 
Corejavainterviewquestions.doc
Corejavainterviewquestions.docCorejavainterviewquestions.doc
Corejavainterviewquestions.docJoyce Thomas
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming languageMd.Al-imran Roton
 
Object Oriented Programming - Polymorphism and Interfaces
Object Oriented Programming - Polymorphism and InterfacesObject Oriented Programming - Polymorphism and Interfaces
Object Oriented Programming - Polymorphism and InterfacesHabtamu Wolde
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javaTech_MX
 
Chapter 5 declaring classes & oop
Chapter 5 declaring classes  & oopChapter 5 declaring classes  & oop
Chapter 5 declaring classes & oopsshhzap
 
Inheritance ppt
Inheritance pptInheritance ppt
Inheritance pptNivegeetha
 

Similar to Java presentation (20)

L7 inheritance
L7 inheritanceL7 inheritance
L7 inheritance
 
L7 inheritance
L7 inheritanceL7 inheritance
L7 inheritance
 
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptxSodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Chap3 inheritance
Chap3 inheritanceChap3 inheritance
Chap3 inheritance
 
Core java by amit
Core java by amitCore java by amit
Core java by amit
 
Core java interview questions
Core java interview questionsCore java interview questions
Core java interview questions
 
Application package
Application packageApplication package
Application package
 
Corejavainterviewquestions.doc
Corejavainterviewquestions.docCorejavainterviewquestions.doc
Corejavainterviewquestions.doc
 
OOP Introduction with java programming language
OOP Introduction with java programming languageOOP Introduction with java programming language
OOP Introduction with java programming language
 
Java 06
Java 06Java 06
Java 06
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
LectureNotes-02-DSA
LectureNotes-02-DSALectureNotes-02-DSA
LectureNotes-02-DSA
 
Object Oriented Programming - Polymorphism and Interfaces
Object Oriented Programming - Polymorphism and InterfacesObject Oriented Programming - Polymorphism and Interfaces
Object Oriented Programming - Polymorphism and Interfaces
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Chapter 5 declaring classes & oop
Chapter 5 declaring classes  & oopChapter 5 declaring classes  & oop
Chapter 5 declaring classes & oop
 
Access modifiers in java
Access modifiers in javaAccess modifiers in java
Access modifiers in java
 
Opp concept in c++
Opp concept in c++Opp concept in c++
Opp concept in c++
 
Inheritance ppt
Inheritance pptInheritance ppt
Inheritance ppt
 

Recently uploaded

The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?Watsoo Telematics
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 

Recently uploaded (20)

The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?What are the features of Vehicle Tracking System?
What are the features of Vehicle Tracking System?
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 

Java presentation

  • 4. Submitted By: 1. S.M.Zahidul Islam 152-15-5925 2. Jakir Hasan 152-15-5617 3. Saniatul Haque 152-15- 5545 4. Akteruzzaman 152-15-5671
  • 5. Submitted To: Md. Zahid Hasan senior lecturer Dept. of CSE Daffodil International University
  • 6. What is inheritance? Inheritance is a fundamental Object Oriented concept A class can be defined as a "subclass" of another class. The subclass inherits all data attributes of its superclass The subclass inherits all methods of its superclass The subclass can: Add new functionality Use inherited functionality Override inherited functionality
  • 7. Benefit of using inheritance  A code can be used again and again  Inheritance in Java enhances the properties of the class, which means that property of the parent class will automatically be inherited by the base class  It can define more specialized classes by adding new details.
  • 8. keyword  Keyword:  Inheritance is declared using the "extends" keyword  To access Super Class from Sub Class we use super keyword
  • 9. EXAMPLE public class SuperClass { Scanner sc = new Scanner(System.in); // Here we take input from Keyboard public double CircleArea(){ double pi=3.1416,num1=0,r=0,CircleAreaResult=0; num1=sc.nextDouble(); // num1 input taken r=sc.nextDouble(); // r input taken CircleAreaResult = pi*num1*(r*r); return CircleAreaResult; } public double TriangleArea(){ double base,hight,TriangleAreaResult = 0; base=sc.nextDouble(); // Here base input taken keyboard hight=sc.nextDouble(); // hight input taken from keyborad TriangleAreaResult = 0.5*base*hight; return TriangleAreaResult; }
  • 10. EXAMPLE(continue) public void Result() { double Result1,Result2; Result1= CircleArea(); Result2= TriangleArea(); System.out.println(“Circle Area : “+Result1+”nTriangle Area : “+Result2); } } public class Main extends SuperClass{ public static void main(String[] args) { SuperClass sp= new SuperClass(); sp.Result(); } }
  • 11. Access Modifiers  Private data fields are not accessible to derived classes  Protected visibility allows data fields to be accessed either by the class defining it or any subclass.  In general, it is better to use private visibility because subclasses may be written by different programmers and it is always good practice to restrict and control access to the superclass data fields  Members (variables and methods) declared with public visibility are accessible, and those with private visibility are not.
  • 12. Polymorphism  Polymorphism come from the two Greek words ‘poly’ meaning many and ‘morphs” meaning forms. The ability to exist in different form is called polymorphism. The same variable or method can perform different tasks; the programmer has the advantage of writing flexible code.
  • 13. Method Overloading  When 2 or more methods in a class have the same method names with different arguments, it is said to be method overloading.  Overloading does not block inheritance from the superclass.  Overloaded methods must have different method signatures.
  • 15. Method Overriding  When a method in a class has the same method name with same arguments as that of the superclass, it is said to be method overriding.  Overriding blocks inheritance from the superclass.  Overridden methods must have same signature.
  • 17. Abstruct class and method  A class that is declared abstract  Ex - abstract class Demo  It may or may not use abstract methods  A method that is declared abstract  A method that is declared without an implementation  Ex - abstract void add(int x, int y);
  • 18. Example public abstract class Shape { //Abstract method i.e no implementation abstract void Area(); } public class Rectangle extends Shape { @Override void Area() { Double area = length * width; } } public class Circle extends Shape { @Override void Area() { Double area = 3.14 * radius*radius; } }
  • 19. Interface  Interfaces are declared using the interface keyword  Interface can contain :  method signature (no implementation)  constant declarations (variable declarations that are declared to be both static and final)
  • 21. Example interface MyInterface { public void method1(); public void method2(); } class XYZ implements MyInterface { public void method1() { System.out.println("implementation of method1"); } public void method2() { System.out.println("implementation of method2"); } public static void main(String arg[]) { MyInterface obj = new XYZ(); obj. method1(); } } Output: implementation of method1
  • 22. Difference Between Interface and Abstract Class  Main difference is methods of a Java interface are implicitly abstract and cannot have implementations. A Java abstract class can have instance methods that implements a default behavior.  Variables declared in a Java interface is by default final. An abstract class may contain non-final variables.  Java interface should be implemented using keyword “implements”; A Java abstract class should be extended using keyword “extends”.  An interface can extend another Java interface only, an abstract class can extend another Java class and implement multiple Java interfaces.  A Java class can implement multiple interfaces but it can extend only one abstract class.  Interface is absolutely abstract and cannot be instantiated; A Java abstract class also cannot be instantiated, but can be invoked if a main() exists.