This document discusses inheritance in Java. It defines inheritance as allowing new classes to reuse properties of existing classes. There are different types of inheritance including single, multilevel, and hierarchical. Key concepts covered include defining subclasses using the extends keyword, using the super keyword to call parent constructors and access parent members, overriding methods, abstract classes and methods, and using the final keyword to prevent overriding or inheritance.
Inheritance allows a derived class to inherit properties from a base or parent class. A derived class inherits attributes and behaviors of the base class and can add its own attributes and behaviors. There are different types of inheritance including single, multilevel, multiple, hierarchical, and hybrid inheritance. Inheritance promotes code reuse and reduces development time.
This document provides an overview of object-oriented programming concepts using C++. It discusses key OOP concepts like objects, classes, encapsulation, inheritance, polymorphism, and dynamic binding. It also covers C++ specific topics like functions, arrays, strings, modular programming, and classes and objects in C++. The document is intended to introduce the reader to the fundamentals of OOP using C++.
Super keyword is a reference variable that is used for refer parent class object. Super keyword is used in java at three level, at variable level, at method level and at constructor level.
This is the presentation file about inheritance in java. You can learn details about inheritance and method overriding in inheritance in java. I think it's can help your. Thank you.
The document discusses constructors and destructors in C++. It describes constructor functions as special member functions that initialize object values when an object is created. It covers default constructors, parameterized constructors, copy constructors, and constructor overloading. Destructors are described as special functions that destroy objects and perform cleanup when objects go out of scope. The key characteristics and uses of constructors and destructors are summarized with examples.
This document discusses inheritance in Java. It defines inheritance as allowing new classes to reuse properties of existing classes. There are different types of inheritance including single, multilevel, and hierarchical. Key concepts covered include defining subclasses using the extends keyword, using the super keyword to call parent constructors and access parent members, overriding methods, abstract classes and methods, and using the final keyword to prevent overriding or inheritance.
Inheritance allows a derived class to inherit properties from a base or parent class. A derived class inherits attributes and behaviors of the base class and can add its own attributes and behaviors. There are different types of inheritance including single, multilevel, multiple, hierarchical, and hybrid inheritance. Inheritance promotes code reuse and reduces development time.
This document provides an overview of object-oriented programming concepts using C++. It discusses key OOP concepts like objects, classes, encapsulation, inheritance, polymorphism, and dynamic binding. It also covers C++ specific topics like functions, arrays, strings, modular programming, and classes and objects in C++. The document is intended to introduce the reader to the fundamentals of OOP using C++.
Super keyword is a reference variable that is used for refer parent class object. Super keyword is used in java at three level, at variable level, at method level and at constructor level.
This is the presentation file about inheritance in java. You can learn details about inheritance and method overriding in inheritance in java. I think it's can help your. Thank you.
The document discusses constructors and destructors in C++. It describes constructor functions as special member functions that initialize object values when an object is created. It covers default constructors, parameterized constructors, copy constructors, and constructor overloading. Destructors are described as special functions that destroy objects and perform cleanup when objects go out of scope. The key characteristics and uses of constructors and destructors are summarized with examples.
This document discusses different types of inheritance in object-oriented programming, including single inheritance where a class extends one other class, multilevel inheritance where a derived class inherits from another derived class, and multiple inheritance where a class can inherit from more than one parent class, which is achieved through interfaces. It provides examples of code implementing single inheritance with a BaseClass and DerivedClass, and multiple inheritance using interfaces Car and Bus implemented by the Vehicle class.
Inheritance allows new classes called derived classes to be created from existing classes called base classes. Derived classes inherit all features of the base class and can add new features. There are different types of inheritance including single, multilevel, multiple, hierarchical, and hybrid. A derived class can access public and protected members of the base class but not private members. Constructors and destructors of the base class are executed before and after those of the derived class respectively.
Java abstract class & abstract methods,Abstract class in java
Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared, but contains no implementation. Abstract classes may not be instantiated, and require subclasses to provide implementations for the abstract methods.
The document provides an introduction to object-oriented programming (OOP) concepts in C++ including objects, classes, abstraction, encapsulation, inheritance, polymorphism, constructors, destructors, and exception handling. It defines each concept and provides examples of how it is implemented in C++ code. For instance, it explains that a class is a user-defined data type that holds its own data members and member functions, and provides an example class declaration. It also discusses polymorphism and provides examples demonstrating method overloading and overriding.
This document discusses inheritance in C++. It defines inheritance as a mechanism that allows classes to acquire properties from other classes. The class that inherits properties is called the derived or child class, while the class being inherited from is called the base or parent class. The key advantages of inheritance are that it saves memory, time, and development efforts by promoting code reuse. The document provides examples of single inheritance with one parent and one child class, and multiple inheritance with a class inheriting from multiple parent classes.
This document discusses implementation of inheritance in Java and C#. It covers key inheritance concepts like simple, multilevel, and hierarchical inheritance. It provides examples of inheritance in Java using keywords like extends, super, this. Interfaces are discussed as a way to achieve multiple inheritance in Java. The document also discusses implementation of inheritance in C# using concepts like calling base class constructors and defining virtual methods.
Our trainer’s having vast experience in real time environment. If anyone has a dream for their career in software programming, then go for java because it is a popular route to establish and fulfill your dreams.
We offer the best quality and affordable training, so you get trained from where you are, from our experienced instructors, remotely using Webex / Gotomeeting.
This document discusses constructor overloading in Java. It defines constructors as special methods that initialize objects. There are two types of constructors: default (no-argument) constructors and parameterized constructors. Constructor overloading allows a class to have multiple constructors that differ in their parameter lists. This allows constructors to perform different initialization tasks depending on the arguments passed. The document provides examples of default, parameterized, and overloaded constructors.
Inheritance allows one class to inherit properties from another class called the base or super class. The new class is called the derived or sub-class. There are different types of inheritance like hierarchical and multi-level inheritance. The visibility of members of the base class depends on whether the inheritance is public, private or protected.
The document discusses the use of the keywords super and this in Java. Super allows subclasses to access methods and fields of the parent class that have been overridden or hidden. It has two forms - to call the parent constructor or to access a hidden parent member. This refers to the current object and is used to avoid name conflicts between instance variables and local variables.
This presentation is Unary operator overloading(prefix).
Here ,I try to describe how to Unary operator overloaded and its types with example. may be you can happily read this.
This document discusses types of inheritance in object-oriented programming including single, multilevel, multiple, hierarchical, and hybrid inheritance. It provides code examples and explanations of:
- Single, multilevel, multiple, hierarchical, and hybrid inheritance structures
- Access specifiers for base and derived classes and their effects
- Calling base class constructors from derived class constructors
- The virtual keyword and dynamic binding in inheritance
The document contains code examples demonstrating inheritance concepts like defining base and derived classes, accessing members of base classes, and calling base class constructors from derived classes. It also provides explanations of multilevel, multiple, and hybrid inheritance with diagrams.
This document discusses inheritance in Java programming. It defines inheritance as a mechanism where a subclass acquires the properties and behaviors of a superclass. It describes the key types of inheritance in Java including single, multilevel, and hierarchical inheritance. It also outlines some advantages, such as code reusability and reliability, and disadvantages, such as increased coupling between classes.
This document discusses keywords in Java including this, super, and final. It explains that this refers to the current object instance and is used to call methods or access fields of the current class. Super is used to call methods or access fields of the parent class. Final is used to declare variables that cannot be reassigned, prevent method overriding, and prevent class inheritance. The document also covers static keywords and how static methods can be called on a class without creating an instance.
This document discusses data types in Java. There are two main types: primitive data types (boolean, char, byte, etc.) and non-primitive types (classes, interfaces, arrays). It explains each of the eight primitive types and provides examples of non-primitive types like classes and arrays. The document also covers type casting (converting between data types), autoboxing/unboxing of primitive types to their corresponding wrapper classes, and the differences between implicit and explicit type casting.
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...Simplilearn
This presentation on the C++ Inheritance tutorial will help you learn about Inheritance in C++ and why we use inheritance in C++. You will also understand modes of inheritance and different types of inheritance in C++. You will get an introduction to inheritance in C++ programming with examples of the different types of inheritance.
Below topics are covered in this presentation:
1. What is inheritance?
2. Why do we use inheritance?
3. Modes of inheritance
4. Types of inheritance
5. Single inheritance
6. Multiple inheritances
7. Multilevel inheritance
8. Hierarchical inheritance
9. Hybrid inheritance
Know the difference between Inheritance and aggregation
Understand how inheritance is done in Java
Learn polymorphism through Method Overriding
Learn the keywords : super and final
Understand the basics of abstract class
The document discusses inheritance in Java. It defines key terminology like superclass, subclass, reusability and the extends keyword. It provides examples of single inheritance with an Employee and Programmer class, and multilevel inheritance with an Animal, Dog and BabyDog class. It also covers method overriding, where a subclass provides its own implementation of a method in the superclass. Dynamic method dispatch is explained, where the version of an overridden method that is executed depends on the object type, not the reference variable type. The document concludes with an overview of method overloading.
This document discusses different types of inheritance in object-oriented programming, including single inheritance where a class extends one other class, multilevel inheritance where a derived class inherits from another derived class, and multiple inheritance where a class can inherit from more than one parent class, which is achieved through interfaces. It provides examples of code implementing single inheritance with a BaseClass and DerivedClass, and multiple inheritance using interfaces Car and Bus implemented by the Vehicle class.
Inheritance allows new classes called derived classes to be created from existing classes called base classes. Derived classes inherit all features of the base class and can add new features. There are different types of inheritance including single, multilevel, multiple, hierarchical, and hybrid. A derived class can access public and protected members of the base class but not private members. Constructors and destructors of the base class are executed before and after those of the derived class respectively.
Java abstract class & abstract methods,Abstract class in java
Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared, but contains no implementation. Abstract classes may not be instantiated, and require subclasses to provide implementations for the abstract methods.
The document provides an introduction to object-oriented programming (OOP) concepts in C++ including objects, classes, abstraction, encapsulation, inheritance, polymorphism, constructors, destructors, and exception handling. It defines each concept and provides examples of how it is implemented in C++ code. For instance, it explains that a class is a user-defined data type that holds its own data members and member functions, and provides an example class declaration. It also discusses polymorphism and provides examples demonstrating method overloading and overriding.
This document discusses inheritance in C++. It defines inheritance as a mechanism that allows classes to acquire properties from other classes. The class that inherits properties is called the derived or child class, while the class being inherited from is called the base or parent class. The key advantages of inheritance are that it saves memory, time, and development efforts by promoting code reuse. The document provides examples of single inheritance with one parent and one child class, and multiple inheritance with a class inheriting from multiple parent classes.
This document discusses implementation of inheritance in Java and C#. It covers key inheritance concepts like simple, multilevel, and hierarchical inheritance. It provides examples of inheritance in Java using keywords like extends, super, this. Interfaces are discussed as a way to achieve multiple inheritance in Java. The document also discusses implementation of inheritance in C# using concepts like calling base class constructors and defining virtual methods.
Our trainer’s having vast experience in real time environment. If anyone has a dream for their career in software programming, then go for java because it is a popular route to establish and fulfill your dreams.
We offer the best quality and affordable training, so you get trained from where you are, from our experienced instructors, remotely using Webex / Gotomeeting.
This document discusses constructor overloading in Java. It defines constructors as special methods that initialize objects. There are two types of constructors: default (no-argument) constructors and parameterized constructors. Constructor overloading allows a class to have multiple constructors that differ in their parameter lists. This allows constructors to perform different initialization tasks depending on the arguments passed. The document provides examples of default, parameterized, and overloaded constructors.
Inheritance allows one class to inherit properties from another class called the base or super class. The new class is called the derived or sub-class. There are different types of inheritance like hierarchical and multi-level inheritance. The visibility of members of the base class depends on whether the inheritance is public, private or protected.
The document discusses the use of the keywords super and this in Java. Super allows subclasses to access methods and fields of the parent class that have been overridden or hidden. It has two forms - to call the parent constructor or to access a hidden parent member. This refers to the current object and is used to avoid name conflicts between instance variables and local variables.
This presentation is Unary operator overloading(prefix).
Here ,I try to describe how to Unary operator overloaded and its types with example. may be you can happily read this.
This document discusses types of inheritance in object-oriented programming including single, multilevel, multiple, hierarchical, and hybrid inheritance. It provides code examples and explanations of:
- Single, multilevel, multiple, hierarchical, and hybrid inheritance structures
- Access specifiers for base and derived classes and their effects
- Calling base class constructors from derived class constructors
- The virtual keyword and dynamic binding in inheritance
The document contains code examples demonstrating inheritance concepts like defining base and derived classes, accessing members of base classes, and calling base class constructors from derived classes. It also provides explanations of multilevel, multiple, and hybrid inheritance with diagrams.
This document discusses inheritance in Java programming. It defines inheritance as a mechanism where a subclass acquires the properties and behaviors of a superclass. It describes the key types of inheritance in Java including single, multilevel, and hierarchical inheritance. It also outlines some advantages, such as code reusability and reliability, and disadvantages, such as increased coupling between classes.
This document discusses keywords in Java including this, super, and final. It explains that this refers to the current object instance and is used to call methods or access fields of the current class. Super is used to call methods or access fields of the parent class. Final is used to declare variables that cannot be reassigned, prevent method overriding, and prevent class inheritance. The document also covers static keywords and how static methods can be called on a class without creating an instance.
This document discusses data types in Java. There are two main types: primitive data types (boolean, char, byte, etc.) and non-primitive types (classes, interfaces, arrays). It explains each of the eight primitive types and provides examples of non-primitive types like classes and arrays. The document also covers type casting (converting between data types), autoboxing/unboxing of primitive types to their corresponding wrapper classes, and the differences between implicit and explicit type casting.
C++ Inheritance Tutorial | Introduction To Inheritance In C++ Programming Wit...Simplilearn
This presentation on the C++ Inheritance tutorial will help you learn about Inheritance in C++ and why we use inheritance in C++. You will also understand modes of inheritance and different types of inheritance in C++. You will get an introduction to inheritance in C++ programming with examples of the different types of inheritance.
Below topics are covered in this presentation:
1. What is inheritance?
2. Why do we use inheritance?
3. Modes of inheritance
4. Types of inheritance
5. Single inheritance
6. Multiple inheritances
7. Multilevel inheritance
8. Hierarchical inheritance
9. Hybrid inheritance
Know the difference between Inheritance and aggregation
Understand how inheritance is done in Java
Learn polymorphism through Method Overriding
Learn the keywords : super and final
Understand the basics of abstract class
The document discusses inheritance in Java. It defines key terminology like superclass, subclass, reusability and the extends keyword. It provides examples of single inheritance with an Employee and Programmer class, and multilevel inheritance with an Animal, Dog and BabyDog class. It also covers method overriding, where a subclass provides its own implementation of a method in the superclass. Dynamic method dispatch is explained, where the version of an overridden method that is executed depends on the object type, not the reference variable type. The document concludes with an overview of method overloading.
This document discusses inheritance in Java programming. It defines inheritance as an "is-a" relationship between a superclass and subclass where the subclass is a more specific version of the superclass. The key concepts covered are method overloading, which allows methods to perform different tasks based on parameters; method overriding, which provides different implementations of methods in subclasses; and dynamic method dispatch, which determines which version of an overridden method to execute based on the object type at runtime.
This document discusses inheritance in Java programming. It defines inheritance as an "is-a" relationship between a superclass and subclass where the subclass is a more specific version of the superclass. The key concepts covered include method overloading, where methods can have the same name but different signatures; method overriding, where subclasses can provide their own implementation of a method in the superclass; and dynamic method dispatch, which determines which version of an overridden method to call at runtime based on the object type.
This document provides an overview of Java fundamentals including classes, objects, encapsulation, abstraction, inheritance, polymorphism and other core OOP concepts. Key points covered include:
- Classes contain variable declarations and method definitions while objects have state, behavior and identity.
- Encapsulation is achieved by declaring class variables as private and providing public get and set methods.
- Abstraction hides certain details and shows only essential information to the user using abstract classes and interfaces.
- Inheritance allows classes to extend functionality from other classes in a hierarchical manner to achieve code reuse.
- Polymorphism allows a single action to be performed in different ways depending on the object used.
The document discusses inheritance in object-oriented programming. It defines inheritance as a mechanism where a subclass inherits properties and behaviors from its parent superclass. The key points are:
- A subclass inherits attributes and methods from its superclass. The subclass can also define its own attributes and methods or override existing superclass methods.
- There are two types of inheritance - single inheritance where a subclass inherits from one superclass, and multiple inheritance which is not supported in Java.
- Access modifiers like public, private, protected determine which members of the superclass are accessible to subclasses. Private members cannot be accessed by subclasses.
- The extends keyword is used to create a subclass that inherits from an existing superclass. The subclass inherits all non
This document discusses key object-oriented programming concepts including encapsulation, inheritance, polymorphism, abstract classes, and interfaces. It provides examples of how encapsulation hides implementation details and inheritance allows classes to inherit properties from superclasses. Polymorphism allows objects to take on multiple forms through inheritance. Abstract classes cannot be instantiated directly but provide a common definition that concrete subclasses implement. Interfaces define behaviors for classes to implement but do not provide implementations.
Inheritance allows reuse of properties and behaviors of an existing class when creating new classes. The existing class is called the base/parent class, while the new class is the derived/child class. The child class inherits all properties and behaviors of the parent class and can define additional properties and behaviors of its own. There are different types of inheritance like single, multilevel, multiple and hierarchical inheritance which define how properties and behaviors are inherited between parent and child classes.
Inheritance is a mechanism in Java that allows one class to acquire the properties (fields and methods) of another class. The class that inherits is called the subclass, and the class being inherited from is called the superclass. This allows code reuse and establishes an is-a relationship between classes. There are three main types of inheritance in Java: single, multilevel, and hierarchical. Method overriding and dynamic method dispatch allow subclasses to provide their own implementation of methods defined in the superclass.
Inheritance allows one class to acquire the properties and behaviors of another class, known as the base or parent class, allowing code reuse and extension of existing classes without modification. There are different types of inheritance like simple, multilevel, and multiple inheritance that build upon the base class in various ways. Inheritance provides benefits like code reuse, extension of existing classes, and ability to override methods of the base class in the derived class.
This document provides an overview of inheritance in object-oriented programming. It defines inheritance as a child class automatically inheriting variables and methods from its parent class. Benefits include reusability, where behaviors are defined once in the parent class and shared by all subclasses. The document discusses how to derive a subclass using the extends keyword, what subclasses can do with inherited and new fields and methods, and how constructors are called following the constructor calling chain. It also covers overriding and hiding methods and fields, type casting between subclasses and superclasses, and final classes and methods that cannot be extended or overridden.
This 5-day Java workshop covers object-oriented programming (OOP) inheritance. The key concepts discussed include the four pillars of OOP - encapsulation, abstraction, inheritance, and polymorphism. Inheritance allows classes to extend existing classes to share common attributes and methods, while also adding new unique functionality. The workshop provides examples of defining parent and child classes, using inheritance, overriding methods, and casting between classes. Resources for further learning about Java and OOP are also listed.
The document discusses access modifiers in Java and their usage with variables, functions, and classes at different levels. It explains that access modifiers like private, protected, default, and public determine whether elements are visible from within the same class, package, subclass, or any class. Private is most restrictive while public is most accessible. It also covers other concepts like static methods, inheritance, polymorphism, abstract classes, interfaces and exception handling in Java.
A class defines the structure and behavior of an object. It groups together data members and member functions that operate on those data members. An object is an instance of a class created by declaring a variable of that class type. Classes in C++ use access specifiers like public and private to control access to members. A class declaration defines the structure while objects are instantiated from the class. Member functions allow manipulating and accessing private data members from outside the class.
Inheritance allows one class to acquire properties of another class. The subclass inherits all properties of the superclass such as methods and fields. The subclass can also define its own unique properties in addition to what it inherits. Inheritance enables code reuse and is a fundamental concept in object-oriented programming.
5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.pptAshwathGupta
Inheritance allows the creation of class hierarchies where subclasses inherit and extend the functionality of parent classes. The document discusses key concepts of inheritance in Java like constructors calling in order of derivation, using the super keyword, method overriding and dynamic dispatch, abstract classes and methods, and final keywords. It provides examples demonstrating multilevel inheritance, overriding methods, and abstract classes.
- Java uses classes and objects to organize code and data. A class defines the blueprint for an object and can contain attributes and methods.
- To create a class, use the "class" keyword followed by the class name. Objects are instances of classes and are created using the "new" keyword.
- The basic structure of a Java program includes creating a class, writing a main method with the public static void signature, and using print statements to output text. Command line arguments can be passed into the main method.
- Inheritance allows classes to inherit and extend the functionality of other classes. Subclasses inherit attributes and behaviors from their parent superclass. This supports code reuse and method overriding for polymorphism.
The document discusses key concepts of classes and objects in C# including defining classes, adding variables and methods, member access modifiers, creating objects, constructors, static members, private constructors, and indexers. It defines classes as user defined data types that can encapsulate data as fields and functions as methods. Objects are instances of classes that allow data and methods to be accessed. Constructors initialize objects, while static members are associated with the class rather than individual objects.
Class is a blueprint for creating objects that share common attributes and behaviors. A class defines the data and methods that describe the object. Classes in Java can contain data members, methods, constructors, nested classes, and interfaces. Objects are instances of classes that occupy memory at runtime and can access class members like variables and methods. Constructors initialize an object when it is created and have the same name as the class. The this keyword refers to the current object in a method or constructor. Command line arguments can be passed to a program as strings and accessed via the args parameter in the main method.
ملفات مساق البرمجة الهدفية (الشيئية) التي يتم تدريسها لطلبة بكالوريوس تكنولوجيا المعلومات وبكالوريوس تطوير نظم الحاسوب في الكلية الجامعية للعلوم والتكنولوجيا.
الملف يضم مفهوم الوراثة Inheritance
إعدادي وتدريسي
Similar to Java Inheritance - sub class constructors - Method overriding (20)
Hierarchical Digital Twin of a Naval Power SystemKerry Sado
A hierarchical digital twin of a Naval DC power system has been developed and experimentally verified. Similar to other state-of-the-art digital twins, this technology creates a digital replica of the physical system executed in real-time or faster, which can modify hardware controls. However, its advantage stems from distributing computational efforts by utilizing a hierarchical structure composed of lower-level digital twin blocks and a higher-level system digital twin. Each digital twin block is associated with a physical subsystem of the hardware and communicates with a singular system digital twin, which creates a system-level response. By extracting information from each level of the hierarchy, power system controls of the hardware were reconfigured autonomously. This hierarchical digital twin development offers several advantages over other digital twins, particularly in the field of naval power systems. The hierarchical structure allows for greater computational efficiency and scalability while the ability to autonomously reconfigure hardware controls offers increased flexibility and responsiveness. The hierarchical decomposition and models utilized were well aligned with the physical twin, as indicated by the maximum deviations between the developed digital twin hierarchy and the hardware.
A review on techniques and modelling methodologies used for checking electrom...nooriasukmaningtyas
The proper function of the integrated circuit (IC) in an inhibiting electromagnetic environment has always been a serious concern throughout the decades of revolution in the world of electronics, from disjunct devices to today’s integrated circuit technology, where billions of transistors are combined on a single chip. The automotive industry and smart vehicles in particular, are confronting design issues such as being prone to electromagnetic interference (EMI). Electronic control devices calculate incorrect outputs because of EMI and sensors give misleading values which can prove fatal in case of automotives. In this paper, the authors have non exhaustively tried to review research work concerned with the investigation of EMI in ICs and prediction of this EMI using various modelling methodologies and measurement setups.
We have compiled the most important slides from each speaker's presentation. This year’s compilation, available for free, captures the key insights and contributions shared during the DfMAy 2024 conference.
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTjpsjournal1
The rivalry between prominent international actors for dominance over Central Asia's hydrocarbon
reserves and the ancient silk trade route, along with China's diplomatic endeavours in the area, has been
referred to as the "New Great Game." This research centres on the power struggle, considering
geopolitical, geostrategic, and geoeconomic variables. Topics including trade, political hegemony, oil
politics, and conventional and nontraditional security are all explored and explained by the researcher.
Using Mackinder's Heartland, Spykman Rimland, and Hegemonic Stability theories, examines China's role
in Central Asia. This study adheres to the empirical epistemological method and has taken care of
objectivity. This study analyze primary and secondary research documents critically to elaborate role of
china’s geo economic outreach in central Asian countries and its future prospect. China is thriving in trade,
pipeline politics, and winning states, according to this study, thanks to important instruments like the
Shanghai Cooperation Organisation and the Belt and Road Economic Initiative. According to this study,
China is seeing significant success in commerce, pipeline politics, and gaining influence on other
governments. This success may be attributed to the effective utilisation of key tools such as the Shanghai
Cooperation Organisation and the Belt and Road Economic Initiative.
2. CS8392- UNIT II INHERITANCE AND INTERFACES 9
• Inheritance – Super classes- sub classes –Protected
members – constructors in sub classes- the Object
class – abstract classes and methods- final methods
and classes – Interfaces – defining an interface,
implementing interface, differences between classes
and interfaces and extending interfaces - Object
cloning -inner classes, Array Lists - Strings
3. Contents
• Inheritance
• Super class and sub class
• Extends and protected keyword
• Types of inheritance
• Single inheritance
• Method overloading and method overriding
• Super keyword and its use
• Subclass constructor
• Object class
5. Inheritance
• Inheritance can be defined as the procedure or mechanism of
acquiring all the properties and behaviour of one class to
another.
• Process of deriving a new class from the existing class is called
inheritance. New class is called sub class and Existing class is
called super class.
• It is the act of mechanism through which the object of one
class can acquire(inherit) the methods and data members of
another class.
6. Super class & Sub class
• Super Class:
• The class whose features are inherited is known as super
class(or a base class or a parent class).
• Sub Class:
• The class that inherits the other class is known as sub
class(or a derived class, extended class, or child class).
• A sub class is a specialized version of the super class.
• The subclass can add its own fields and methods in
addition to the superclass fields and methods.
8. Example:
• 2Dpoint and 3Dpoint
2Dpoint – superclass and 3Dpoint – subclass
• Person and Student
Person – superclass and Student – subclass
• Person and Employee
Person – superclass and Student – subclass
9. Example of Inheritance
• Superclass Fields : x, y
• Subclass Fields : x & y (Inherited), z
2DPoint
3DPoint
10. Reusability
• Inheritance supports the concept of “reusability”, i.e.
• When we want to create a new class, which is more specific
to a class that is already existing, we can derive our new
class from the existing class.
• By doing this, we are reusing the fields and methods of the
existing class.
11. Syntax - extends keyword
class SubClassName extends SuperClassName
{
//fields and methods
}
The meaning of extends is to increase the functionality.
Eg. Class student extends person
{
}
12. protected keyword
• A class’s private members are accessible only within the class
itself.
• A superclass’s protected members can be accessed
• by members of that superclass,
• by members of its subclasses and
• by members of other classes in the same package
13. Types of Inheritance
• Single inheritance - One sub
class is derived from one
super class
• multilevel inheritance - A
sub class is derived from
another sub class which is
derived from a super class.
• hierarchical inheritance-
Two or more sub classes
have the same super class
• Person – Student
• Animal – Dog
Student – Exam – Result
Person – Student
Person – Employee
https://nptel.ac.in/courses/106105191/13
Person
Student
Student
Exam
Result
Person
Student Employee
14. Purpose of inheritance
• Inheritance is the process by which objects of one class
acquire the properties and methods of another class.
• It provides the idea of reusability.
• We can add additional features to an existing class without
modifying it by deriving a new class from it- Extendibility
• Save development time
15. Single inheritance
• Deriving a single sub class from a single super class is called
single inheritance. It is derived using the keyword ‘extends’
class A
{ }
class B extends A
{ }
• class A is the super class from which the class B is derived.
• Class B inherits all the public and protected members of class
A but class B cannot access private members of class A.
18. Output
Explanation
• Superclass Circle has a method display()
• Subclass Sphere has a method with the same name display()
• When calling display() with the subclass object, subclass’s display()
method is invoked.
19. Method Overloading
• Methods in a class having the same method name with
different number and type of arguments is said to be
method overloading.
• Method overloading is done at compile time.
• Number of parameter can be different.
• Types of parameter can be different.
20. Method Overriding
• The methods in the super class and its sub classes have the
same method name with same type and the same number
of arguments (same signature), this is referred as method
overriding.
• Method in sub classes overrides the method in super class.
• Eg. display() method in class Circle & class Sphere.
22. Class Poll
In which java oops feature one object can acquire all
the properties and behaviours of the parent object?
• Encapsulation
• Inheritance
• Polymorphism
• None of the above
23. Class Poll
What is subclass in java?
A subclass is a class that extends another class
A subclass is a class declared inside a class
Both above.
None of the above.
24. Class Poll
If class B is subclassed from class A then which is the
correct syntax
• class B:A{}
• class B extends A{}
• class B extends class A{}
• class B implements A{}
25. Super Keyword
1. To access the data members of immediate super
class when both super and sub class have member
with same name.
2. To access the method of immediate super class
when both super and sub class have methods with
same name.
3. To explicitly call the no-argument(default) and
parameterized constructor of super class
26. 1. To access the data members of immediate
super class – both super and sub class should
have same member variable name
27. class Animal
{
String color="white";
}
class Dog extends Animal
{
String color="black";
void printColor()
{
System.out.println(color); //prints color of Dog class
System.out.println(super.color); //prints color of Animal class
}
}
class TestSuper1{
public static void main(String args[]){
Dog d=new Dog();
d.printColor();
} }
28. • In the above example, Animal and Dog both classes have a common
property color. If we print color property, it will print the color of
current class by default. To access the parent property, we need to
use super keyword as super.color
29. 2. To access methods of immediate super
class – both super class and subclass should
have same method name and method
signature (Overridden method).
30. /* Base class Person */
class Person
{
void message()
{
System.out.println("This is person class");
}
}
/* Subclass Student */
class Student extends Person
{
void message()
{
System.out.println("This is student class");
}
// Note that display() is only in Student
class
void display()
{
message();
super.message();
}
}
31. /* Driver program to test */
class Test
{
public static void main(String args[])
{
Student s = new Student();
// calling display() of Student
s.display();
}
}
32. 3. To explicitly call the no-argument(default)
and parameterized constructor of super class
34. subclass constructor
• Constructor which is defined in the subclass is called as
subclass constructor.
• Used to call the superclass constructor and construct the
instance variables of both superclass and subclass.
• Subclass constructor uses the keyword super() to invoke the
superclass constructor
• On object creation of sub class, first super class constructor
and then sub class constructor will be called.
35. Constructors in sub classes
super() can call both
• default as well as
• parameterized constructors
depending upon the situation.
36.
37.
38. Points to Remember
• Call to super() must be first statement in subclass constructor.
• If a constructor does not explicitly invoke a superclass constructor, the
Java compiler automatically inserts a call to the no-argument(default)
constructor of the superclass.
39. Class Poll
Order of execution of constructors in Java Inheritance is
• Base to derived class
• Derived to base class
• Random order
• none
41. Class Poll
Advantage of inheritance in java programming is/are
• Code Re-usability
• Class Extendibility
• Save development time
• All
42. The object class
• Object class is present in java.lang package.
• Every class in Java is directly or indirectly derived from
the Object class.
• If a Class does not extend any other class, then it is direct
child class of Object and if extends other class then it is an
indirectly derived. Therefore the Object class methods are
available to all Java classes.
• Hence Object class acts as a root of inheritance hierarchy in
any Java Program.
43. Method Description
public final Class getClass() returns the Class class object of this object. The Class class can further be used to
get the metadata of this class.
public int hashCode() returns the hashcode number for this object.
public boolean equals(Object obj) compares the given object to this object.
protected Object clone() throws
CloneNotSupportedException
creates and returns the exact copy (clone) of this object.
public String toString() returns the string representation of this object.
public final void notify() wakes up single thread, waiting on this object's monitor.
public final void notifyAll() wakes up all the threads, waiting on this object's monitor.
public final void wait(long timeout)throws
InterruptedException
causes the current thread to wait for the specified milliseconds, until another
thread notifies (invokes notify() or notifyAll() method).
public final void wait(long timeout,int
nanos)throws InterruptedException
causes the current thread to wait for the specified milliseconds and nanoseconds,
until another thread notifies (invokes notify() or notifyAll() method).
public final void wait()throws
InterruptedException
causes the current thread to wait, until another thread notifies (invokes notify() or
notifyAll() method).
protected void finalize()throws Throwable is invoked by the garbage collector before object is being garbage collected.
44. How does these methods work?
• https://www.geeksforgeeks.org/object-class-in-java/
• Object class documentation Java SE 7
• https://docs.oracle.com/javase/7/docs/api/java/lang/Object.html
• Object class Tutorial
• https://docs.oracle.com/javase/tutorial/java/IandI/objectclass.html
45. Method overloading Method overriding
• Methods in a class having the same
method name with different number
and type of arguments (different
signature) is said to be method
overloading.
• Method overloading is done at
compile time. Thus Compile Time
Polymorphism is achieved.
• Number of parameter can be
different.
• Types of parameter can be different.
• The methods in the super class and
its sub classes have the same method
name with same type and the same
number of arguments (same
signature), this is referred as method
overriding.
• Method overriding is one of the way
by which java achieve Run Time
Polymorphism.
• Number of parameters are same.
• Types of parameter are same.