0% found this document useful (0 votes)
75 views12 pages

Unit II Inheritance-Class 1

Object-oriented programming organizes programs around data objects rather than functions. It uses inheritance so that child classes can inherit properties and behaviors from parent classes. C++ and Java both use object-oriented programming and inheritance. In Java, the syntax for inheritance is class ChildClass extends ParentClass, allowing the child class to inherit fields and methods from the parent class while also adding its own fields and methods. Inheritance promotes code reuse.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views12 pages

Unit II Inheritance-Class 1

Object-oriented programming organizes programs around data objects rather than functions. It uses inheritance so that child classes can inherit properties and behaviors from parent classes. C++ and Java both use object-oriented programming and inheritance. In Java, the syntax for inheritance is class ChildClass extends ParentClass, allowing the child class to inherit fields and methods from the parent class while also adding its own fields and methods. Inheritance promotes code reuse.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

OBJECT ORIENTED PROGRAMMING

UNIT II - INHERITANCE
Process-Oriented Model:

• Series of linear steps

• Code acting on data

• Procedural languages such as C

Object-Oriented Programming:

• Organizes a program around its data (that is, objects) and a set of
well-defined interfaces to that data

• Data controlling access to code


 
Object-Oriented Programming:

• C++ was invented by Bjarne Stroustrup in 1979, while he was working


at Bell Laboratories in Murray Hill, New Jersey. Stroustrup initially
called the new language “C with Classes.” However, in 1983, the name
was changed to C++. C++ extends C by adding object-oriented
features. Because C++ is built on the foundation of C, it includes all of
C’s features, attributes, and benefits.

• Java was conceived by James Gosling, Patrick Naughton, Chris Warth,


Ed Frank, and Mike Sheridan at Sun Microsystems, Inc. in 1991. It
took 18 months to develop the first working version. This language
was initially called “Oak,” but was renamed “Java” in 1995.
Syntax for class:
Inheritance
• Inheritance in java can be defined as a mechanism where a new class is
derived from an existing class for reusability
(or)
• Inheritance is the process by which one object acquires the
properties of another object
(or)
• Inheritance allows the classes to inherit or acquire the properties and
methods of other classes

• The class that is inherited is called the parent class, or superclass, or


base class
• The class that inherits other class is called the child class or subclass or
derived class or extended class
Java Inheritance Example

The relationship between the two classes is Programmer IS-A Employee.


In OOP an important feature is Reusability which is very use full in two major issues of
development :
* Saving Time
* Saving Memory

In C++/Java the mechanism implements this reusability is Inheritance.

Syntax of Java Inheritance


class Subclass-name extends Superclass-name  
{  
  //methods and fields  
}  
class Employee
{  
String Empname="Sam";
int age=25;
float salary=40000;  
}  
class Programmer extends Employee
{  
 int bonus=10000;  
}
class Company
{
 public static void main(String args[]){  
  Programmer p=new Programmer();  
System.out.println("Employee Name :"+p.Empname);
System.out.println("Age :"+p.age);
  System.out.println("Programmer salary is:"+p.salary);  
  System.out.println("Bonus of Programmer is:"+p.bonus);  
}  
}  
 Output
• Even though A is a superclass for B, it is also a completely independent, stand-
alone class.

• Being a superclass for a subclass does not mean that the superclass cannot be
used by itself.

• A subclass can be a superclass for another subclass.

• Java does not support the inheritance of multiple superclasses into a single
subclass

• No class can be a superclass of itself.

You might also like