Looking for a Tutor Near You?

Post Learning Requirement » x
Ask a Question
x
x

Direction

x

Ask a Question

x

Hire a Tutor

Inheritance

Published in: C++
18 Views

This ppt represents the type of inheritance in programming language.

Roshin S / Sharjah

2 years of teaching experience

Qualification: Masters in computer science

Teaches: IELTS, OET, GED, GATE, Computer Science, English, Science, MS Office, Web Development, C Language, C++, Computer, Maths

Contact this Tutor
  1. Inheritance It is a mechanism in which one object acquires all the properties and behaviors of a parent object. Inheritance represents the IS-A relationship which is also known as a parent-child relationship. Uses • For Method Overriding (so run time polymorphism can be achieved). • For Code Reusability. Types ClassA Classa I) Single Cla SSA ClassB ClassC 2) Multilevel Classa ClassA 3) Hierarchical
  2. ClassA ClassC 4) Multiple Single level Inheritance Classe ClassB ClassA ClassD 5) Hybrid ClassC When a class inherits another class, it is known as a single inheritance. class Animal { void eat() ) class Dog extends Animal{ void bark(){ System.out println("barking...
  3. class Testlnheritance { public static void main(String args[]){ Dog d=new Dog(); d bark(); d eat(); Multilevel Inheritance Output eating... barking When there is a chain of inheritance, it is known as multilevel inheritance. class Animal { void eat() { System.out.println("eating... "); } class Dog extends Animal { void bark(){System.out.println("barking... ) class BabyDog extends Dog{ void weep() { System.out.println("weeping... }
  4. class TestInheritance2 { public static void main(String args[]){ BabyDog d=new BabyDog(); d weep(); d. bark(); d eat(); Output weeping... barking.. eating... Hierarchical Inheritance When two or more classes inherits a single class, inheritance. class Animal { void eat() { } it is known as hierarchical
  5. class Dog extends Animal { void bark(){System.out.println("barking... } class Cat extends Animal { void meow() { .. "); ) class TestInheritance3 { public static void main(String args[]){ Cat c=new Cat(); c.meow(); c. eat(); Output meowmg. eating... barking...
  6. Method Overloading If a class has multiple methods having same name but different in parameters, it is known as Method Overloading. Method Overriding If subclass (child class) has the same method as declared in the parent class, it is known as method overriding in Java Super Keyword The super keyword in Java is a reference variable which is used to refer immediate parent class object. Final Keyword The final keyword in java is used to restrict the user. The java final keyword can be used in many context. Final can be: variable method class
  7. Polymorphism It is a concept by which we can perform a single action in different ways. Polymorphism is derived from 2 Greek words: poly and morphs. Runtime polymorphism / Dynamic Method Dispatch It is a process in which a call to an overridden method is resolved at runtime rather than compile-time. iava instanceof operator It is used to test whether the object is an instance of the specified type (class or subclass or interface). Abstract Class A class which is declared with the abstract keyword is known as an abstract class in Java. It can have abstract and non-abstract methods (method with the body). Abstraction Abstraction is a process of hiding the implementation details and showing only functionality to the user.
  8. Interface An interface in Java is a blueprint of a class. It has static constants and abstract methods. The interface in Java is a mechanism to achieve abstraction. There can be only abstract methods in the Java interface, not method body. It is used to achieve abstraction and multiple inheritance in Java. interface Printable { void print(); interface Showable{ void show(); class A 7 implements Printable,Showable{ public void print() { System.out.println("Hello");) public void show() { } public static void main(String args[]){ A 7 obj new A 7(); obj.print(); obj.show();
  9. Package It is a group of similar types of classes, interfaces and sub-packages. Package in java can be categorized in two form, built-in package and user-defined package. There are many built-in packages such as java, lang, awt, javax, swing, net, io, util, sql etc. Access Modifiers There are two types of modifiers in Java. access modifiers and non-access modifiers. Private: The access level of a private modifier is only within the class. It cannot be accessed from outside the class. Default: The access level of a default modifier is only within the package. It cannot be accessed from outside the package. If you do not specify any access level, it will be the default. Protected: The access level of a protected modifier is within the package and outside the package through child class. If you do not make the child class, it cannot be accessed from outside the package. Public: The access level of a public modifier is everywhere. It can be accessed from within the class, outside the class, within the package and outside the package.
  10. Encapsulation in Java is a process of wrapping code and data together into a single unit. Array. It is an object which contains elements of a similar data type. The elements of an array are stored in a contiguous memory location. It is a data structure where we store similar elements. We can store only a fixed set of elements in a Java array. l) Single dimensional Array 2) Multidimensional Array