• Home
  • Courses

    About Courses

    • Core Java
    • JDBC
    JDBC

    JDBC

    Free
    Read More
  • Features
    • Portfolio
    • About Us
    • FAQs
  • Gallery
  • Blog
  • Contact
      • Cart

        0
    Hacked by Katib | Turkish Hacker | SpyHackerz.OrgHacked by Katib | Turkish Hacker | SpyHackerz.Org
    • Home
    • Courses

      About Courses

      • Core Java
      • JDBC
      JDBC

      JDBC

      Free
      Read More
    • Features
      • Portfolio
      • About Us
      • FAQs
    • Gallery
    • Blog
    • Contact
        • Cart

          0

      JAVA TECHNOLOGIES

      • Home
      • All courses
      • JAVA TECHNOLOGIES
      • Core Java
      LP CoursesJAVA TECHNOLOGIESCore Java
        • Lecture1.1
          What is Java? 30 min
        • Lecture1.2
          JDK Installation Steps 30 min
        • Lecture1.3
          First Program in Java 30 min
        • Lecture1.4
          C++ vs Java 30 min
        • Lecture1.5
          Java Comments 30 min
        • Lecture1.6
          Java Operators 30 min
        • Lecture1.7
          Java Loop Control 30 min
        • Lecture1.8
          Decision making 30 min
        • Lecture1.9
          Object Oriented Programming 30 min
        • Lecture1.10
          Objects and Classes 30 min
        • Lecture1.11
          Java Inheritance 30 min
        • Lecture1.12
          Static,non-static and final 30 min
        • Lecture1.13
          Abstract Class vs Interface 30 min
        • Lecture1.14
          Overloading vs Overriding 30 min

        Java Inheritance

        Inheritance is a compile-time mechanism in Java that allows you to extend a class (called the base class or superclass) with another class (called the derived class or subclass). In Java, inheritance is used for two purposes:

        1. class inheritance – create a new class as an extension of another class, primarily for the purpose of code reuse. That is, the derived class inherits the public methods and public data of the base class. Java only allows a class to have one immediate base class, i.e., single class inheritance.

        2. interface inheritance – create a new class to implement the methods defined as part of an interface for the purpose of subtyping. That is a class that implements an interface “conforms to” (or is constrained by the type of) the interface. Java supports multiple interface inheritance

        class inheritance, Java uses the keyword extends and for interface inheritance, Java uses the keyword implements.

        Syntax:
        public class derived-class-name extends base-class-name {
        // derived class methods extend and possibly override
        // those of the base class
        }

        public class class-name implements interface-name {
        // class provides an implementation for the methods
        // as specified by the interface
        }

        [php]
        class A {
        int x;
        int y;
        int get(int p, int q){
        x=p; y=q; return(0);
        }
        void Show(){
        System.out.println(x);
        }
        }

        class B extends A{
        public static void main(String args[]){
        A a = new A();
        a.get(5,6);
        a.Show();
        }
        void display(){
        System.out.println("B");
        }
        }
        [/php]

        [php]
        public interface Employee {
        void RaiseSalary( double d );
        double GetSalary();
        }

        public class TA implements Employee {
        void RaiseSalary( double d ) {
        // actual code here
        }
        double GetSalary() {
        // actual code here
        }
        }
        [/php]

        Prev Objects and Classes
        Next Static,non-static and final

        Leave A Reply Cancel reply

        Your email address will not be published. Required fields are marked *

        All Courses

        • JAVA TECHNOLOGIES

        Latest Courses

        Core Java

        Core Java

        Free
        JDBC

        JDBC

        Free
        logo-eduma-the-best-lms-wordpress-theme

        contactus@tech2our.com

        Company

        • About Us
        • Blog
        • Contact

        Links

        • Courses
        • Events
        • FAQs

        Support

        • Documentation
        • Forums
        • Language Packs

        Copyright © 2012-2017 Tech2Our.com. All Rights Reserved.

        • Privacy
        • Terms
        • Sitemap