SlideShare a Scribd company logo
1 of 12
Lecture 6
Encapsulation




        Object Oriented Programming
         Eastern University, Dhaka
                 Md. Raihan Kibria
What encapsulation means
   Broadly, it means keeping variables and
    methods together inside a class. In the
    following demo we will create a JFrame.
    We will also add two JPanels. We want
    each of the panels two have certains
    things:
      One text field
      One button
public class EncapsulationDemo {
  public static void main(String[] args) {
   JFrame jframe = new JFrame();
   jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   jframe.setBounds(0, 0, 300, 200);
   jframe.getContentPane().setLayout(new FlowLayout());

     MyPanel m = new MyPanel();
     jframe.getContentPane().add(m);

     m = new MyPanel();
     jframe.getContentPane().add(m);

     jframe.setVisible(true);
    }
}

class MyPanel extends JPanel{
  public MyPanel() {
    super();
    this.setBackground(Color.GRAY);
    this.addComponents();
  }

    private void addComponents(){
      JTextField text = new JTextField("Hello");
      this.add(text);
      JButton btn = new JButton("submit");
      this.add(btn);
    }
Here is the output




Notice whenever we make a new MyPanel we get a
JTextBox and a JButton for free

This happens because the method addComponents() gets
called. In other words, we have encapsulated the behaviour
of the object in the class definition
Encapsulation conclusion
   It is the essence of object oriented
    programming
   Keeping functionalities/behavior embedded
    into an object gives us the benefit of having
    free functionality when we create an object
   We cannot do this in struct of C
Inheritance
   Inheritance can be achived when we
    “extend” a class using 'extends” keyword.
   The super class or base class is the original
    class. The child class is the new class.

   Example: Jframe looks like this:
Code to make a JFrame
 import javax.swing.JFrame;

 public class InheritanceDemoFrame {

     public static void main(String[] args) {
       JFrame jframe = new JFrame();
       jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       jframe.setBounds(0, 0, 300, 200);
       jframe.setVisible(true);
     }
 }



Note that the JFrame shown can be maximized, closed,
minimized, etc.
Let us extend the JFrame
public class InheritanceDemoFrame extends JFrame{

    InheritanceDemoFrame(){
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setBounds(0, 0, 300, 200);
      setLayout(new FlowLayout());

        JButton jbutton = new JButton("Test button");
        getContentPane().add(jbutton);

        JTextField jtext = new JTextField();
        getContentPane().add(jtext);
        jtext.setText("Hello");
    }

    public static void main(String[] args) {
      InheritanceDemoFrame f = new InheritanceDemoFrame();
      f.setVisible(true);
    }
}
The output




Lesson: By “extend”ing the JFrame we still have
maximize, close, minimize buttons. We have added
more things without loosing any previous
functionalities
Inheritance features
   We can extend a class if it is not marked
    final
   When we extends we inherit its public,
    protected methods and variables
   We can further extends and inherited class
   Inheritance is a key feature of object
    oriented programming
More features of inheritance
   The base class is called super class
   The child class is called sub class
   Members (variables and methods) of the
    super class are accessible from the sub
    class using super keyword. The other way
    access is not possible or make any sense
More features of inheritance
   The members of the sub class can be referred to using “this”
           class A{
             public int i;

               public void increment(){
                 i = i + 1;
               }
           }

           class B extends A{

               public int i;

               public void increment(){
                 super.i = super.i + 1;
               }

               public void incrementMe(){
                 this.i = this.i + 1;
               }

               public void incrementDad(){
                 super.increment();
               }

More Related Content

What's hot (12)

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
 
L03 Software Design
L03 Software DesignL03 Software Design
L03 Software Design
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
 
Assignment 7
Assignment 7Assignment 7
Assignment 7
 
Polymorphism in java
Polymorphism in javaPolymorphism in java
Polymorphism in java
 
Lab 4 jawapan (sugentiran mane)
Lab 4 jawapan (sugentiran mane)Lab 4 jawapan (sugentiran mane)
Lab 4 jawapan (sugentiran mane)
 
Core java oop
Core java oopCore java oop
Core java oop
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Introduction to php oop
Introduction to php oopIntroduction to php oop
Introduction to php oop
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Method Overloading In Java
Method Overloading In JavaMethod Overloading In Java
Method Overloading In Java
 
Javapolymorphism
JavapolymorphismJavapolymorphism
Javapolymorphism
 

Viewers also liked

Viewers also liked (9)

Oop lecture2
Oop lecture2Oop lecture2
Oop lecture2
 
Calendario portada
Calendario portadaCalendario portada
Calendario portada
 
Oop lecture1
Oop lecture1Oop lecture1
Oop lecture1
 
Oop lecture9 12
Oop lecture9 12Oop lecture9 12
Oop lecture9 12
 
Oop lecture8
Oop lecture8Oop lecture8
Oop lecture8
 
Presentacion viernes 20 [compatibility mode]
Presentacion viernes 20 [compatibility mode]Presentacion viernes 20 [compatibility mode]
Presentacion viernes 20 [compatibility mode]
 
Cwgd
CwgdCwgd
Cwgd
 
Oop lecture9 13
Oop lecture9 13Oop lecture9 13
Oop lecture9 13
 
Oop lecture9 11
Oop lecture9 11Oop lecture9 11
Oop lecture9 11
 

Similar to Oop lecture6

Chapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).pptChapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).ppthenokmetaferia1
 
Lecture 5 Inheritance
Lecture 5 InheritanceLecture 5 Inheritance
Lecture 5 Inheritancebunnykhan
 
Introduction to OOP with PHP
Introduction to OOP with PHPIntroduction to OOP with PHP
Introduction to OOP with PHPMichael Peacock
 
Demystifying Object-Oriented Programming - PHP UK Conference 2017
Demystifying Object-Oriented Programming - PHP UK Conference 2017Demystifying Object-Oriented Programming - PHP UK Conference 2017
Demystifying Object-Oriented Programming - PHP UK Conference 2017Alena Holligan
 
Keyword of java
Keyword of javaKeyword of java
Keyword of javaJani Harsh
 
Chapter 11.2
Chapter 11.2Chapter 11.2
Chapter 11.2sotlsoc
 
I am sorry but my major does not cover programming in depth (ICT) an.pdf
I am sorry but my major does not cover programming in depth (ICT) an.pdfI am sorry but my major does not cover programming in depth (ICT) an.pdf
I am sorry but my major does not cover programming in depth (ICT) an.pdfseamusschwaabl99557
 
Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#Abid Kohistani
 
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdfalliedscorporation
 

Similar to Oop lecture6 (20)

Oop lecture9
Oop lecture9Oop lecture9
Oop lecture9
 
Chapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).pptChapter 5 (OOP Principles).ppt
Chapter 5 (OOP Principles).ppt
 
Lecture 7.pdf
Lecture 7.pdfLecture 7.pdf
Lecture 7.pdf
 
Chap-3 Inheritance.pptx
Chap-3 Inheritance.pptxChap-3 Inheritance.pptx
Chap-3 Inheritance.pptx
 
Lecture 5 Inheritance
Lecture 5 InheritanceLecture 5 Inheritance
Lecture 5 Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Spring hibernate jsf_primefaces_intergration
Spring hibernate jsf_primefaces_intergrationSpring hibernate jsf_primefaces_intergration
Spring hibernate jsf_primefaces_intergration
 
Introduction to OOP with PHP
Introduction to OOP with PHPIntroduction to OOP with PHP
Introduction to OOP with PHP
 
‫Chapter3 inheritance
‫Chapter3 inheritance‫Chapter3 inheritance
‫Chapter3 inheritance
 
Demystifying Object-Oriented Programming - PHP UK Conference 2017
Demystifying Object-Oriented Programming - PHP UK Conference 2017Demystifying Object-Oriented Programming - PHP UK Conference 2017
Demystifying Object-Oriented Programming - PHP UK Conference 2017
 
6 Inheritance
6 Inheritance6 Inheritance
6 Inheritance
 
Diifeerences In C#
Diifeerences In C#Diifeerences In C#
Diifeerences In C#
 
Keyword of java
Keyword of javaKeyword of java
Keyword of java
 
Chapter 11.2
Chapter 11.2Chapter 11.2
Chapter 11.2
 
I am sorry but my major does not cover programming in depth (ICT) an.pdf
I am sorry but my major does not cover programming in depth (ICT) an.pdfI am sorry but my major does not cover programming in depth (ICT) an.pdf
I am sorry but my major does not cover programming in depth (ICT) an.pdf
 
Computer programming 2 -lesson 4
Computer programming 2  -lesson 4Computer programming 2  -lesson 4
Computer programming 2 -lesson 4
 
C++ presentation
C++ presentationC++ presentation
C++ presentation
 
11.Object Oriented Programming.pdf
11.Object Oriented Programming.pdf11.Object Oriented Programming.pdf
11.Object Oriented Programming.pdf
 
Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#Polymorphism in C# Function overloading in C#
Polymorphism in C# Function overloading in C#
 
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
3. Section 3 � Complete functionality on listing screen (1.5 marks.pdf
 

More from Shahriar Robbani (7)

Group111
Group111Group111
Group111
 
SQL
SQLSQL
SQL
 
Oop lecture9 10
Oop lecture9 10Oop lecture9 10
Oop lecture9 10
 
Oop lecture4
Oop lecture4Oop lecture4
Oop lecture4
 
Oop lecture7
Oop lecture7Oop lecture7
Oop lecture7
 
Oop lecture5
Oop lecture5Oop lecture5
Oop lecture5
 
Oop lecture3
Oop lecture3Oop lecture3
Oop lecture3
 

Recently uploaded

How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 

Recently uploaded (20)

How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 

Oop lecture6

  • 1. Lecture 6 Encapsulation Object Oriented Programming Eastern University, Dhaka Md. Raihan Kibria
  • 2. What encapsulation means  Broadly, it means keeping variables and methods together inside a class. In the following demo we will create a JFrame. We will also add two JPanels. We want each of the panels two have certains things:  One text field  One button
  • 3. public class EncapsulationDemo { public static void main(String[] args) { JFrame jframe = new JFrame(); jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jframe.setBounds(0, 0, 300, 200); jframe.getContentPane().setLayout(new FlowLayout()); MyPanel m = new MyPanel(); jframe.getContentPane().add(m); m = new MyPanel(); jframe.getContentPane().add(m); jframe.setVisible(true); } } class MyPanel extends JPanel{ public MyPanel() { super(); this.setBackground(Color.GRAY); this.addComponents(); } private void addComponents(){ JTextField text = new JTextField("Hello"); this.add(text); JButton btn = new JButton("submit"); this.add(btn); }
  • 4. Here is the output Notice whenever we make a new MyPanel we get a JTextBox and a JButton for free This happens because the method addComponents() gets called. In other words, we have encapsulated the behaviour of the object in the class definition
  • 5. Encapsulation conclusion  It is the essence of object oriented programming  Keeping functionalities/behavior embedded into an object gives us the benefit of having free functionality when we create an object  We cannot do this in struct of C
  • 6. Inheritance  Inheritance can be achived when we “extend” a class using 'extends” keyword.  The super class or base class is the original class. The child class is the new class.  Example: Jframe looks like this:
  • 7. Code to make a JFrame import javax.swing.JFrame; public class InheritanceDemoFrame { public static void main(String[] args) { JFrame jframe = new JFrame(); jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jframe.setBounds(0, 0, 300, 200); jframe.setVisible(true); } } Note that the JFrame shown can be maximized, closed, minimized, etc.
  • 8. Let us extend the JFrame public class InheritanceDemoFrame extends JFrame{ InheritanceDemoFrame(){ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(0, 0, 300, 200); setLayout(new FlowLayout()); JButton jbutton = new JButton("Test button"); getContentPane().add(jbutton); JTextField jtext = new JTextField(); getContentPane().add(jtext); jtext.setText("Hello"); } public static void main(String[] args) { InheritanceDemoFrame f = new InheritanceDemoFrame(); f.setVisible(true); } }
  • 9. The output Lesson: By “extend”ing the JFrame we still have maximize, close, minimize buttons. We have added more things without loosing any previous functionalities
  • 10. Inheritance features  We can extend a class if it is not marked final  When we extends we inherit its public, protected methods and variables  We can further extends and inherited class  Inheritance is a key feature of object oriented programming
  • 11. More features of inheritance  The base class is called super class  The child class is called sub class  Members (variables and methods) of the super class are accessible from the sub class using super keyword. The other way access is not possible or make any sense
  • 12. More features of inheritance  The members of the sub class can be referred to using “this” class A{ public int i; public void increment(){ i = i + 1; } } class B extends A{ public int i; public void increment(){ super.i = super.i + 1; } public void incrementMe(){ this.i = this.i + 1; } public void incrementDad(){ super.increment(); }