0% found this document useful (0 votes)
10 views25 pages

Template: Study Material: Insert The Details Within The

Uploaded by

rajrahatalcr1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views25 pages

Template: Study Material: Insert The Details Within The

Uploaded by

rajrahatalcr1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Template: Study Material

Insert the details within the < quotes >


<CO>: <22412>: <Java Programming>: <Inheritance >: <LO1a>: <Study Material>
<Chetashri Bhusari> <02/11/2020> <Prof.Vijay Patil >

Key words Learning Objective: Diagram/ Picture


Super,Inheritance,parent Students should understand concept of inheritance and its
class,sub class,child types (brief)
class,

Key Questions Concept Map

What do you mean by


inheritance?
Which keyword is used
to implement Inheritance and its Type
inheritance?

Explanation of Concept Key Definitions/ Formulas


 Inheritance is one of the cornerstones of object- Inheritance is one of the
oriented programming because it allows the cornerstones of object-
creation of hierarchical classifications. oriented programming
 Using inheritance, you can create a general class because it allows the creation
that defines traits common to a set of related of hierarchical classifications
items.
 This class can then be inherited by other, more
specific classes, each adding those things that are
unique to it.
Solved word Problem  In the terminology of Java, a class that is inherited
What do you mean by is called a superclass.
inheritance?  The class that does the inheriting is called a
 Inheritance can subclass.
be defined as the  Therefore, a subclass is a specialized version of a
process where one class superclass.
acquires the properties  It inherits all of the members defined by the
(methods and fields) superclass and adds its own, unique elements.
of another  To inherit a class, you simply incorporate the
 The class which definition of one class into another by using the
inherits the extends keyword.
properties of
other is known
as subclass
(derived class,
child class)
and the class whose
properties are inherited
is known as superclass
(base class, parent
class).
It is an important
part
of OOPs (Object Application of Concept/ Examples in real life Link to YouTube/ OER/ video
Oriented The class ‘Car’ inherits its properties from the class https://www.geeksforgeeks.o
programming ‘Automobiles’ which inherits some of its properties from rg/inheritance-in-c/
system). https://www.youtube.com/w
another class ‘Vehicles’. atch?v=nixQyPIAnOQ

Key Take away from this LO1a: students should understand basic about inheritance .
Insert the details within the < quotes >
<CO>: <22412>: <Java Programming>: <Inheritance>: <LO1b>: <Study Material>
<ChetashriBhusari> <02/11/2020> <Prof.Vijay Patil>

Key words Learning Objective: Diagram/ Picture


Super,Inheritance,parentclass,subclass,child Students should understand concept of single inheritance.
class,

Key Questions Concept Map

What do you mean by single inheritance?


Write down syntax of single inheritance.
single Example and
Inheritancce implemenatation
Inheritance

Explanation of Concept Key Definitions/ Formulas


 Inheritance is one of the cornerstones of object- Inheritance is one of the
oriented programming because it allows the creation of cornerstones of object-
hierarchical classifications. oriented programming
 Single Inheritance: - When a subclass is derived simply because it allows the creation
from its parent’s class then this mechanism is known as of hierarchical classifications
singleinheritance. Inthis type there is only one child
class and one parentclass.
 Syntax of single inheritance:
class BaseClass
Solved word Problem
Example of single Inheritance: {
//methods and fields
class Faculty
{ }
float salary=30000; classDerivedClassextendsBaseClass
}
class Science extends Faculty {
{ //methods and fields
float bonous=2000;
public static void main(String args[]) }
{ Example:
Science obj=new Science();
System.out.println("Salary is:"+obj.salary); class A
System.out.println("Bonous {
is:"+obj.bonous);
} //methods and fields
} }
Class B extends A
{
//methods and fields
Application of Concept/ Examples in real life Link to YouTube/ OER/ video
The real life example of inheritance is child and parents, all the
properties of father are inherited by his son

Key Take away from this LO1b: students should understand concept of single inheritance

Template: Study Material


Template: Study Material
Insert the details within the < quotes >
<CO>: <22412>: <Java Programming>: <Inheritance >: <LO1c>: <Study Material>
<Chetashri Bhusari> <02/11/2020> <Prof.Vijay Patil >

Key words Learning Objective: Diagram/ Picture


Super,Inheritance,parent Students should understand concept of multilevel inheritance
class,sub class,child
class,

Key Questions Concept Map

What do you mean by


multilevel inheritance?
Which keyword is used
to implement Inheritance and its Type
inheritance?

Explanation of Concept Key Definitions/


 Inheritance is one of the cornerstones of object-oriented Formulas
programming because it allows the creation of Inheritance is one of the
hierarchical classifications. cornerstones of object-
 Using inheritance, you can create a general class that oriented programming
defines traits common to a set of related items. because it allows the
 This class can then be inherited by other, more specific creation of hierarchical
classes, each adding those things that are unique to it. classifications
 In the terminology of Java, a class that is inherited is
called a superclass.
Solved word Problem  The class that does the inheriting is called a subclass.
What do you mean by  Therefore, a subclass is a specialized version of a
inheritance? superclass. It inherits all of the members defined by the
 Inheritance can superclass and adds its own, unique elements.
be defined as the  To inherit a class, you simply incorporate the definition
process where one class of one class into another by using the extends keyword
acquires the properties  Multilevel inheritance :
(methods and fields)  When a class is derived from already derived class then
of another this mechanism is known as multilevel inheritance.
 The class which  The derived class is called as subclass or child class for its
inherits the parents' class and this parent class work as child class for
properties of its just above parent class.
other is known  Multilevel inheritance can go up to any level
as subclass
(derived class,
child class)
and the class whose
properties are inherited
is known as superclass
(base class, parent
class).
It is an important
part
of OOPs (Object Application of Concept/ Examples in real life: Real life application Link to YouTube/ OER/
Oriented of inheritance can be chid inherits all properties from video
programming parents.whereas parents inherit all properties from grandparents.
system).

Key Take away from this LO: students should understand concept of multilevel inheritance
Template: Study Material
Insert the details within the < quotes >
<CO>: <22412>: <Java Programming>: <Inheritance >: <LO1d>: <Study Material>
<Chetashri Bhusari> <02/11/2020> <Prof.Vijay
Patil >
Key words Learning Objective: Diagram/
Super,Inheritance,parent Students should understand concept of hierarchical inheritance Picture
class,sub class,child class,

Key Questions Concept Map

What do you mean by Examples


inheritance?
Which keyword is used to
implement inheritance? hierarchical Inheritance

syntax

Explanation of Concept Key


 Inheritance is one of the cornerstones of object-oriented Definitions/
programming because it allows the creation of hierarchical Formulas
classifications. Inheritance is
 Using inheritance, you can create a general class that defines one of the
traits common to a set of related items. cornerstones
 This class can then be inherited by other, more specific classes, of object-
each adding those things that are unique to it. oriented
 In the terminology of Java, a class that is inherited is called a programming
superclass. because it
Solved word Problem  The class that does the inheriting is called a subclass. allows the
What do you mean by  Therefore, a subclass is a specialized version of a superclass. It creation of
hierarchical inheritance? inherits all of the members defined by the superclass and adds its hierarchical
own, unique elements. classifications
 To inherit a class, you simply incorporate the definition of one
• In hierarchical class into another by using the extends keyword.
inheritance one class is
extended by many
subclasses.
• It is one to many
relationships.
• Many programming
problems can be tasked
into a hierarchy where
certain features of one
level
are shared by many • In hierarchical inheritance one class is extended by many subclasses.
others below the level • It is one to many relationships.
• Many programming problems can be tasked into a hierarchy where
certain features of one level
are shared by many others below the level
Application of Concept/ Examples in real life: Link to
YouTube/
OER/ video

Examples

hierarchical
Inheritance

syntax

Key Take away from this LO: students should understand concept of hierarchical inheritance
Template: Study Material
Insert the details within the < quotes >
<CO>: <22412>: <Java Programming>: <Inheritance >: <LO2a>: <Study Material>
<Chetashri Bhusari> <04/02/2021> <Prof.Vijay Patil >

Key words Learning Objective: Diagram/ Picture


Super,Inheritance,parent class,sub Students should understand Differentiate between
class,child class, overloading and overriding

Key Questions Concept Map

What do you mean by method


overloading?
What do you mean by method
overriding?
Explanation of Concept: Key Definitions/
Method Overloading: Formulas
 Method Overloading means to define
different methods with the same name but
different parameters lists and different
definitions.
 It is used when objects are required to
perform similar task but using different input
parameters that may vary either in number
or type of arguments.
 Overloaded methods may have different
return types.
 Method overloading allows user to achieve
the compile time polymorphism.
Method Overloading:
 There may be situation when we want an
object to respond to the same method but
have different behavior when that method is
called.
 This is possible by defining a method in the
subclass that has the same name, same
arguments and same return type as a method
in the superclass.
 Then, when that method is called, the
method defined in the subclass is invoked
and executed instead of the one in the
superclass. This is known as overriding.
 In overriding return types and constructor
parameters of method should match.
Solved word Problem Example of method overriding:
Example of method overloading class A
class Sample {
{ int i;
int addition(int i, int j) A(int a, int b)
{ returni + j ; } {
String addition(String s1, String s2) i=a+b;
{ return s1 + s2; } }
double addition(double d1, double d2) void add()
{ return d1 + d2; } {
} System.out.println(“Sum of a & b is=” +i);
class AddOperation }
{ }
public static void main(String args[]) class B extends A
{ {
Sample sObj = new Sample(); int j;
System.out.println(sObj.addition(1,2)); B(int a, int b, int c)
System.out.println(sObj.addition("Hello {
","World")); super(a,b); j=a+b+c;
System.out.println(sObj.addition(1.5,2.2)); }
} void add()
} {
super.add();
System.out.println(“Sum of a, b & c”+j);
}
}
class MethodOverride
{
public static void main(String args[])
{
B b=new B(10,20,30);
b.add(); Link to YouTube/
}Application of Concept/ Examples in real life: OER/ video
}The real life example of inheritance is child and
parents, all the properties of father are inherited by his
son.

Key Take away from this LO2a: students should differentiate between method overloading and overriding concept
Template: Study Material
Insert the details within the < quotes >
<CO>: <22412>: <Java Programming>: <Inheritance >: <LO2a>: <Study Material>
<Chetashri Bhusari> <04/02/2021> <Prof.Vijay Patil >

Key words Learning Objective: Diagram/ Picture


Super,Inheritance,parent class,sub Students should understand Differentiate between
class,child class, overloading and overriding

Key Questions Concept Map

What do you mean by method


overloading?
What do you mean by method
overriding?
Explanation of Concept: Key Definitions/
Method Overloading: Formulas
 Method Overloading means to define
different methods with the same name but
different parameters lists and different
definitions.
 It is used when objects are required to
perform similar task but using different input
parameters that may vary either in number
or type of arguments.
 Overloaded methods may have different
return types.
 Method overloading allows user to achieve
the compile time polymorphism.
Method Overloading:
 There may be situation when we want an
object to respond to the same method but
have different behavior when that method is
called.
 This is possible by defining a method in the
subclass that has the same name, same
arguments and same return type as a method
in the superclass.
 Then, when that method is called, the
method defined in the subclass is invoked
and executed instead of the one in the
superclass. This is known as overriding.
 In overriding return types and constructor
parameters of method should match.
Solved word Problem Example of method overriding:
Example of method overloading class A
class Sample {
{ int i;
int addition(int i, int j) A(int a, int b)
{ returni + j ; } {
String addition(String s1, String s2) i=a+b;
{ return s1 + s2; } }
double addition(double d1, double d2) void add()
{ return d1 + d2; } {
} System.out.println(“Sum of a & b is=” +i);
class AddOperation }
{ }
public static void main(String args[]) class B extends A
{ {
Sample sObj = new Sample(); int j;
System.out.println(sObj.addition(1,2)); B(int a, int b, int c)
System.out.println(sObj.addition("Hello {
","World")); super(a,b); j=a+b+c;
System.out.println(sObj.addition(1.5,2.2)); }
} void add()
} {
super.add();
System.out.println(“Sum of a, b & c”+j);
}
}
class MethodOverride
{
public static void main(String args[])
{
B b=new B(10,20,30);
b.add(); Link to YouTube/
}Application of Concept/ Examples in real life: OER/ video
}The real life example of inheritance is child and
parents, all the properties of father are inherited by his
son.

Key Take away from this LO2a: students should differentiate between method overloading and overriding concept
Template: Study Material
Insert the details within the < quotes >
<CO>: <22412>: <Java Programming>: <Inheritance >: <LO2c>: <Study Material>
<Chetashri Bhusari> <04/02/2021> <Prof.Vijay Patil >

Key words Learning Objective: Diagram/ Picture


Super,parent class,static StStudents should understand concept of abstract class
member,abstract class, and methods ,static

Key Questions Concept Map

Write short note on abstract class . Methods in


Write short note on static member. Java

Concept of
static
abstract class
members
and method
Explanation of Concept: Key Definitions/
Abstract class : Formulas
► A class which is declared as abstract is known
as an abstract class.
► It can have abstract and non-abstract
methods.
► It needs to be extended and its method
implemented.
► Abstraction is a process of hiding the
implementation details and showing only
functionality to the user. Another way, it
shows only important things to the user and
hides the internal details.
► A method must be always redefined in a
subclass of an abstract class, as abstract class
does not contain method body. Thus abstract
makes overriding compulsory.
► Class containing abstract method must be
declared as a abstract.
► You cannot declare abstract constructor, and
so, objects of abstract class cannot be
instantiated.
Static members :
 When a number of objects are created from
the same class, each instance has its own
copy of class variables. But this is not the case
when it is declared as static.
 Static method or a variable is not attached to
a particular object, but rather to the class as
a whole. They are allocated when the class is
loaded.
 If some objects have some variables which
are common, then these variables or
methods must be declared static.
 To create a static variable, precede its
declaration with keyword static. Static
Solved word Problem variables need not be called on any object
Example of abstract class Example of static member:
abstract class A Int a; // normal variable static int a;
{ //static variable classs
abstract void disp(); void show() {
{ int a,b;
System.out.println(“show method is not static int c;
abstract”); }
}} class statictest
class B extends A {
{ public static void main(String args[])
void disp() {
{ s ob1=new s(); s ob2=new s(); s ob3=new s();
System.out.println(“inside class B”); }
} }
} In above program variable a and b are declared as
class test int variable whereas the variable c is declared as
{ static variable. Static variable will be common
public static void main(String args[]) between all the objects.
{
B b = new B(); b.disp();
b.show();
}
}
Output :
show method is not abstract inside class B

Link to YouTube/
Application of Concept/ Examples in real life: OER/ video
Creation of array linked list

Key Take away from this LO2c: Students should understand concept of abstract class and methods ,static members
Template: Study Material
Insert the details within the < quotes >
<CO>: <22412>: <Java Programming>: <Inheritance >: <LO3>: <Study Material>
<Chetashri Bhusari> <04/02/2021> <Prof.Vijay Patil >

Key words Learning Objective: Diagram/ Picture


Students should understand concept of interface.
Interface, extending ,accessing,
implements

Key Questions Concept Map

What do you mean by method


interface ?
How to Access interface? Interface
How to implements interface?
Accessing
interface

Extending
Interface
Explanation of Concept: Key Definitions/
Formulas
► An interface is collection of abstract method and it
is defined much likeclass.
► Writing an interface is similar to the class, with
abstract methods and final field.
► This means that interface do not specify any code
to implement those methods & data fields
containing only constants.
► Interfaces cannot be instantiated they can be only
implemented by the classes or extended by other
Interfaces.
► Interfaces are design to support dynamic method
resolution at runtime
► The general from of interface is access interface
interface name
{
variable declaration; method declaration;
}
► Access is either public or not used when no access
specifier is included, then default access result and
interface is only available to other member of the
package in which it is declared.
► For e.g.-
public interface IF4IA
{
String Lecture=”JPR”; int benches=35;
void display();
}
Implementing Interface:
Syntax:-
class class_name implements interface
{
//body
} OR
class class_name extends class_name
Solved word Problem implements interface 1,2
Syntax:-
class class_name implements Accessing Interface Variables and Method:
interface  An interface can use to declare set of constants that
{ can be used in different classes.
//body  is similar to creating header files in c++ to contain a
} OR large no. of constants.
class class_name extends  Such interface does not contain methods, there is
class_name no need to warry about implementing methods.
implemnts interface 1,2  All variable declared in interface must be constant.
For e.g.- inteface shape
{ multiple inheritance through interface:
public String baseclass="Shape";  It is type of interface where a derived class may
public void draw(); have more than one parent class.
}  It is not possible in case of Java as you cannot have
class circle implements shape two parent classes at the parent level, instead
{ there can be one class and one interface at parent
public void draw() level to achieve multiple inheritance.
{  Interface is similar to classes but can contain final
System.out.println("Circle drawn variable and abstract methods. Interfaces can be
here"); implemented to a derived class.
}
}

Program of interface:
int x=12;
}
interface two
{
int y=10;
void display();
} Link to YouTube/
class demo implemets one, two Application of Concept/ Examples in real life: OER/ video
{ The real life example of inheritance is child and parents, all the
int a=x; int b=y; properties of father are inherited by his son.
public vioddisplay()
{
System.out.println("x in interfece
one" +x); System.out.println("y in
interfece one" +y);
System.out.println("x & y"+(x+y));
}
public void disp()
{
System.out.println("Value access
from interface one:" +a);
System.out.println("Value access
from interface two:" +b);
}
}
class multipleinterface
{
public static void main(String
args[])
{
demo d= new demo(); d.display();
d.disp();
}
}
For e.g : - interface sports
{
int sport_wt=5;
public void disp();
}
class test
{
int roll_no;
String name
int m1,m2;
test(int r, String nm, int m11,int
m12)
{
roll_no=r;
name=nm;
m1=m11;
=m12;
}
}
class result extends test
implements sports
{
result (int r, String nm, int m11,int
m12)
{
super (r,nm,m11,m12);
}
public void disp()
{
System.out.println("Roll no :
"+roll_no);
System.out.println("Name :
"+name);
System.out.println("sub1 : "+m1);
System.out.println("sub2 : "+m2);
System.out.println("sport_wt :
"+sport_wt);
int t=m1+m2+sport_wt
System.out.println("total : "+t);
}
public static void main(String
args[])
{
result r= new
result(101,"abc",75,75); r.disp();
}
}

Key Take away from this LO3: students should concept of interface
Template: Study Material
Insert the details within the < quotes >
<CO>: <22412>: <Java Programming>: <Inheritance >: <LO4>: <Study Material>
<Chetashri Bhusari> <04/02/2021> <Prof.Vijay Patil >

Key words Learning Objective: Diagram/ Picture


Package,import, Create user defined package for given problem.

Key Questions Concept Map

What do you mean by package?


How to import package?
What is Syntax of package?
•Concept
Package •Syntax of package
•Types of package
•Examples

Explanation of Concept: Key Definitions/


Formulas
► Package is nothing more than the way we organize
files into different directories according to their
functionality, usability as well as category they
should belongs to.
► Packaging also helps us to avoid class name
collision when we use the same class name as that
of others.
► Packages act as containers for classes.
package pakage_name;
For e.g.
package A; class ABC
{
___________
___________
___________
___________
Solved word Problem }
Advantage of Java Package:
 Package names are 1) Java package is used to categorize the classes and
written in all lower case interfaces so that they can be easily maintained.
to avoid conflict with 2) Java package provides access protection.
the names of classes or 3) Java package removes naming collision.
interfaces.
 All class name begins
with an uppercase letter
and method name begin Accessing package:
with lowercase letters  Package can be accessed using keyword import.
 For e.g. :- double x=java  There are 2 ways to access java system packages:
lang.Math.sqrt(x);  Package can be imported using import
where lang is package keyword and the wild card(*) but
name and Math is drawback of this shortcut approach is that
classname it is difficult to determine from which
Creating Package: package a particular member name.
 Declare a package at  Syntax: import package_name.*; For e.g. import
beginning of a file java.lang.*;
using  The package can be accessed by using
 syntax: - dot(.) operator and can be terminated
package using semicolon(;)
package_name;  Syntax: import package1.package2.classname; For
 Define the class that is e.g. VP.IF.IF4I.IF4IA
to be put inside the
package and declare it
as public.
 Create subdirectory
under the directory
where the main source
files are stored.
 Store the listing as Link to YouTube/
classname.java files in Application of Concept/ Examples in real life: OER/ video
the subdirectory A real-life example is when you download a movie, song, or
created. game, you make a different folder for each category like
 Compile the file, this movie, song, etc. In the same way, a group of packages in java
creates .class file in the is just like a library.
subdirectory.

Key Take away from this LO3: students should concept of package
Template: Study Material
Insert the details within the < quotes >
<CO>: <22412>: <Java Programming>: <Inheritance >: <LO5>: <Study Material>
<Chetashri Bhusari> <04/02/2021> <Prof.Vijay Patil >

Key words Learning Objective: Diagram/ Picture


Package,import,static Students should understand concept of package with import
statement ,static import and adding class to interface

Key Questions Concept Map

What do you mean by import?


What are the different ways to
import?
•import statement
Package •static import
•Examples

Explanation of Concept: Key Definitions/


► The import keyword is used to import built-in Formulas
packages & user defined packages. So that
your class can refer a class that is in another
package by directly using its name.
 Import only the classes from particular
package.
For eg:-
import java.util.*;
Class MyDate extends Date
{
//Body of Class
}
 Import the class you want to use particular
package.

For eg:-
import java.util.date;
Class MyDate extends Date
{
//Body of Class
}
Solved word Problem Static Import:-
Static import is a feature that expands capabilities
Adding class to a package of import keywords. It is used to import Static
Structure:- Package p1 public member of a class.
class A Using static import, it is impossible to refer to
{ static member directly without its class name.
/body of class
} There are 2 general forms of Static import
statement.
Create a file outside of package
Import only one static member the classes from
which consists of main method particular package.
import p1.*; import static package.classname static member
class B name
{ Import static java.lang.Math.sqrt;
public static void main (String Import all static members of a class
args[]) For eg:-
Import static package.classname
{
// create object of class which is
in package

}
}

Link to YouTube/
Application of Concept/ Examples in real life: OER/ video
A real-life example is when you download a movie, song, or
game, you make a different folder for each category like
movie, song, etc. In the same way, a group of packages in java
is just like a library.

Key Take away from this LO5: students should concept of package with import and static import statement

You might also like