Lecture Slide - Week 5
Lecture Slide - Week 5
PROGRAMMING
USING JAVA
Method Overriding
• If subclass (child class) has the same method as declared in the parent
class, it is known as method overriding in Java.
• In other words, If a subclass provides the specific implementation of
the method that has been declared by one of its parent class, it is
known as method overriding.
❑Usage of Overriding
• Method overriding is used to provide the specific implementation of a
method which is already provided by its superclass.
• Method overriding is used for runtime polymorphism.
RULES FOR METHOD OVERRIDING
• The method must have the same name as in the parent class
• The method must have the same parameter as in the parent class.
• There must be an IS-A relationship (inheritance).
EXAMPLE OF METHOD OVERRIDING
//Creating a parent class.
class Vehicle{
//defining a method
void run(){System.out.println("Vehicle is running");}
}
//Creating a child class
class Bike2 extends Vehicle{
//defining the same method as in the parent class
void run(){System.out.println("Bike is running safely");}
Step:1
null
obj
Step:2 a=0
b=0
c=0
obj Child object
Step:3
a=10
b=100
c=0
obj
Child object
Step:4 a=200
b=20
c=220
obj
Child object
PROBLEM DESCRIPTION: NEED OF SUPER KEYWORD
O/P:
Parent first10100
Child second20020
Sum is 220
PROBLEM DESCRIPTION: NEED OF SUPER KEYWORD
Output
• The first form of super acts somewhat like this, except that it always refers to
the immediate superclass variables of the subclass in which it is used.
super.variable
SUPER CAN BE USED TO INVOKE PARENT CLASS VARIABLE
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{ //class with a main method
public static void main(String args[]){
} Output:
class TestSuper1{ //class with a main method
black
public static void main(String args[]){ white
Dog d=new Dog(); //object of sub class
d.printColor();
}}
SUPER CAN BE USED TO INVOKE PARENT CLASS METHOD
• The second form of super acts somewhat like this, except that it always refers to the
immediate superclass method of the subclass in which it is used.
• This usage has the following general form:
super.method()
SUPER CAN BE USED TO INVOKE PARENT CLASS METHOD
class Animal{
void eat()
{System.out.println("eating...");}
}
class Dog extends Animal{
void eat()
{System.out.println("eating bread...");}
void bark()
{System.out.println("barking...");}
void work(){
super.eat();
bark();
}
}
class TestSuper2{
public static void main(String args[]){
Dog d=new Dog();
d.work();
}}
SUPER CAN BE USED TO INVOKE PARENT CLASS METHOD
class Animal{
void eat()
{System.out.println("eating...");}
}
class Dog extends Animal{
void eat()
{System.out.println("eating bread...");}
void bark()
{System.out.println("barking...");}
void work(){
Output
super.eat();
bark();
}
eating...
} barking...
class TestSuper2{
public static void main(String args[]){
Dog d=new Dog();
d.work();
}}
USING SUPER TO CALL SUPERCLASS CONSTRUCTORS
• A subclass can call a constructor defined by its superclass by use of the following
form of super:
super(arg-list);
• Here , arg-list specifies any arguments needed by the constructor in the
superclass.super( )
• It always be the first statement executed inside a subclass constructor.
• When a subclass calls super(), it is calling the constructor of its immediate
superclass. Thus , super() always refers to the superclass immediately above the
calling class.
USING SUPER TO CALL SUPERCLASS CONSTRUCTORS
class Animal{
Animal(){System.out.println("animal is created");}
}
class Dog extends Animal{
Dog(){
super(); //first statement
System.out.println("dog is created");
}
}
class TestSuper3{
public static void main(String args[]){
Dog d=new Dog();
}}
USING SUPERTO CALL SUPERCLASS CONSTRUCTORS
class Animal{
Animal(){System.out.println("animal is created");}
}
class Dog extends Animal{
Dog(){ Output
super(); //first statement
System.out.println("dog is created");
animal is created
}
dog is created
}
class TestSuper3{
public static void main(String args[]){
Dog d=new Dog();
}}
NOTE:
In java programming, multiple and hybrid inheritance is supported through interface only.
TYPES OF INHERITANCE IN JAVA
SINGLE INHERITANCE
class Animal
{
void eat()
{System.out.println("eating...");}
}
Note: When a class inherits another class, it is
class Dog extends Animal{ known as a single inheritance. In the example
void bark() given below, Dog class inherits the Animal
{System.out.println("barking...");} class, so there is the single inheritance.
}
class TestInheritance{
public static void main(String args[]){ Dog d=new
Dog();
d.bark();
d.eat();
}}
MULTILEVEL INHERITANCE
class Animal{
void eat() When there is a chain of inheritance, it is
{System.out.println("eating...");} known as multilevel inheritance. As you can
} see in the example given below, BabyDog class
class Dog extends Animal{ inherits the Dog class which again inherits the
void bark() Animal class, so there is a multilevel
{System.out.println("barking...");} inheritance.
}
class BabyDog extends Dog{
void weep(){System.out.println("weeping...");}
}
class TestInheritance2{
public static void main(String args[]){
BabyDog d=new BabyDog();
d.weep();
d.bark();
d.eat();
}
}
MULTILEVEL INHERITANCE
class Animal{
void eat() When there is a chain of inheritance, it is
{System.out.println("eating...");} known as multilevel inheritance. As you can
} see in the example given below, BabyDog class
class Dog extends Animal{ inherits the Dog class which again inherits the
void bark() Animal class, so there is a multilevel
{System.out.println("barking...");} inheritance.
}
class BabyDog extends Dog{
void weep(){System.out.println("weeping...");}
}
class TestInheritance2{ OUTPUT:
public static void main(String args[]){
BabyDog d=new BabyDog(); weeping...
d.weep(); barking...
d.bark(); eating...
d.eat();
}
}
HIERARCHICAL INHERITANCE
class Animal{
void eat()
{System.out.println("eating...");}
}
class Dog extends Animal{
When two or more classes inherits a single
void bark()
class, it is known as hierarchical inheritance.
{System.out.println("barking...");}
In the example given below, Dog and Cat
}
classes inherits the Animal class, so there is
class Cat extends Animal{
hierarchical inheritance.
void meow()
{System.out.println("meowing...");}
}
class TestInheritance3{
public static void main(String args[]){
Cat c=new Cat();
c.meow();
c.eat();
//c.bark();//C.T.Error
}}
HIERARCHICAL INHERITANCE
class Animal{
void eat()
{System.out.println("eating...");}
}
class Dog extends Animal{
When two or more classes inherits a single
void bark()
class, it is known as hierarchical inheritance.
{System.out.println("barking...");}
In the example given below, Dog and Cat
}
classes inherits the Animal class, so there is
class Cat extends Animal{
hierarchical inheritance.
void meow()
{System.out.println("meowing...");}
}
class TestInheritance3{
public static void main(String args[]){ OUTPUT
Cat c=new Cat(); meowing...
c.meow(); eating...
c.eat();
//c.bark();//C.T.Error
}}
MULTIPLE INHERITANCE
When a class extends multiple classes i.e., known as multiple inheritance. For Example:
• Consider a scenario where A, B and C are three classes. The C class inherits A
and B classes. If A and B classes have same method and you call it from child
class object.
• There will be ambiguity to call method of A or B class.
WHY MULTIPLE INHERITANCE IS NOT SUPPORTED IN JAVA?
class A{
void add()
{a =10;
b=5;
c=a+b;} }
class B{
void add()
{a =10;
b=5;
c=15;
d=a+b+c;}
class C extends A,B{//suppose if it were
Public Static void main(String args[]){
C obj=new C();
obj.add();//Now which add() method would be invoked?
} }
WHY MULTIPLE INHERITANCE IS NOT SUPPORTED IN JAVA?
• So whether you have same method or different, there will be compile time error
now.
• Therefore, Inheritance is called Compile Time Mechanism.
class A{
void add()
{a =10;
b=5;
c=a+b;}
}
class B{
Output:
void sub()
'{' expected
{
class C extendsA,B
a =10;
b=5;
c= a-b;
}
class C extends A,B{
Public Static void main(String args[]){
C obj=new C();
obj.add();
}
}
Overloading vs. Overriding
Visibility modifiers determine which class members are accessible and which
are not.
37
The protected Modifier
• If a class declared as the final then we can't creates the child class that is
Class
inheritance concept is not applicable for final classes.
• If a variable declared as the final then we need to look for the type of variables
Variables
and then correspondingly actions need to be taken (discussed later in the slides).
EXAMPLE
final classTest
{
void methodOne( )
{
System.out.println(“Protected Member Access Modifier”);
}
}
classTest1 extendsTest
{ public static void main(String args[])
{
Test t=newTest();
Every method present inside a final class is always final t.methodOne();
Test1 b = newTest1();
by default whether we are declaring or not. But every b.methodOne();
variable present inside a final class need not be final. Test c = newTest1();
c.methodOne();
}
}
FINAL VARIABLES IN INSTANCE VARIABLES
• If the value of a variable is varied from object to object such type of variables are
called instance variables.
• For every object a separate copy of instance variables will be created.
• For the instance variables it is not required to perform initialization explicitly jvm will
always provide default values.
FINAL VARIABLES IN INSTANCE VARIABLES
• For the final instance variables we should perform initialization before constructor
completion. That is the following are various possible places for this.
• Initialization while declaration, instance initialization block, and constructor.
FINAL VARIABLES IN STATIC VARIABLES
• If the static variable declare as final then compulsory we should perform initialization
explicitly whether we are using or not otherwise we will get compile time error.(The
JVM won't provide any default values)
• For the final static variables we should perform initialization before class loading
completion otherwise we will get compile time error. That is the following are
possible places.
• Initialization while declaration and inside static block.
FINAL VARIABLES IN LOCAL VARIABLES
• Consider the example of an email, the user does not know about the complex
details such as what happens just after sending an email, which protocol is used by
the server to send the message. Therefore, we just need to mention the address of the
receiver, type the content and click the send button.
• For example sending sms, you just type the text and send the message. You don't
know the internal processing about the message delivery.
HOWTOACHIEVEABSTRACTION IN JAVA?
• Abstract methods are methods with no implementation and without a method body.
They do not contain any method statement.
• An abstract method is declared with an abstract keyword.
• The declaration of an abstract method must end with a semicolon ;
• The child classes which inherit the abstract class must provide the implementation of
these inherited abstract methods.
Don’t know
Public class covid19 implementa
{ tion Public abstract class covid19 Abstract
Public void vaccine () { Methods are
{ Public abstract void vaccine (); implemented in
} // ends with ; the child class
} Know // no cur
} only
declaration
WHICH ONE IS VALID?
• public abstract void m1(){} // compilation error: abstract method cannot have a body
• public void m1(); // compilation error: missing method body or abstract method
• public abstract void m1();
• public void m1(){}
ABSTRACT CLASS
• A class which contains the abstract keyword in its declaration is known as abstract class.
• an abstract class is like a guideline or a template that has to be extended by its child classes for the
implementation.
• Need of Abstract class: Sometimes implementation of a class is not complete or having partial
implementation.
•Abstract classes may or may not contain abstract methods, i.e., methods without body (
public void get(); )
• But, if a class has at least one abstract method, then the class must be declared abstract.
• If a class is declared abstract, it cannot be instantiated.
• To use an abstract class, you have to inherit it from another class, provide implementations to the abstract
methods in it.
• If you inherit an abstract class, you have to provide implementations to all the abstract methods in it.
CASE 1: CASE 1 & 2
public class Main
{
abstract void wheel();
public static void main(String[] args) {
System.out.println("Hello World");
Main m =new Main(); CASE 2:
}
} abstract public class Main
{
} abstract void wheel();
public static void main(String[] args) {
System.out.println("Hello World");
Main m =new Main();
}
}
CASE 1: CASE 1 & 2
public class Main Output
{
abstract void wheel(); Main.java:9:error:Mainisnotabstractanddoesnotoverrideabstractmethodwhe
public static void main(String[] args) { el()inMain
System.out.println("Hello World");
Main m =new Main(); CASE 2:
}
} abstract public class Main
{
} abstract void wheel();
public static void main(String[] args) {
System.out.println("Hello World");
Output Main m =new Main();
}
Main.java:14: error: Main is abstract; cannot be instantiated
}
CONSIDERA SCENARIOTHATYOU HAVETO BUILDYOUR FINALYEAR
PROJECT
• You want to make a new mobile app with some different features.
• You want to add features like
• Calling
• Moving
• Video Calling
PROGRAM
Main.java:20: error: main2 is not abstract and does not override abstract
method engine() in Main
CASE 4
abstract public class Main
{
abstract void wheel();
abstract void engine();
public static void main(String[] args) {
System.out.println("Hello World");
//Main m =new Main();
}
OUTPUT
Hello World
CASE 5
abstract public class Main
{
abstract void wheel();
abstract void engine();
public static void main(String[] args) {
System.out.println("Hello World");
// Main m =new Main();
}
}
OUTPUT
Main.java:20: error: main2 is not abstract and does not override abstract
method engine() in Main
AN ABSTRACT CLASS CAN HAVE A CONSTRUCTOR BUT CAN NOT
CREATE AN OBJECT.
public class child1 extends parent{
public abstract class parent{ Int m;
Int i; Int n;
Int j; Public child1 (int i, int j, int m, int n)
{
} this.i=i;
this.j=j;
this.m=m;
this.n=n;
}
public static void main(String[] args) {
Child1 c=new child1(1,2,3,4);
}
}
AN ABSTRACT CLASS CAN HAVE A CONSTRUCTOR BUT CAN NOT
CREATE AN OBJECT.
public class child1 extends parent{ class child2 extends parent{
abstract class parent{ Int m;
Int i; Int x;
Int n; Int y;
Int j; Public child1 (int i, int j, int m, int n) Public child1 (int i, int j, int x, int y)
{ {
} this.i=i; this.i=i;
this.j=j; this.j=j;
this.m=m; this.x=x;
this.n=n; this.y=y;
} }
public static void main(String[] args) {
Child1 c=new child1(1,2,3,4);
}
}
• Duplicate code
• Waste a lot of time
AN ABSTRACT CLASS CAN HAVE A CONSTRUCTOR BUT CAN NOT
CREATE AN OBJECT. (SOLUTION)
public abstract class parent{ public class child1 extends parent{
Int i; Int m; public class child2 extends parent{
Int j; Int n; Int x;
Public parent (int i, int j) Public child1 (int i, int j, int m, int n) Int y;
{ { Public child2 (int i, int j, int x, int y)
this.i=i; super(i,j); {
this.j=j this.m=m; super(i,j);
} this.n=n; this.x=x;
} this.y=y;
public static void main(String[] args) { }
Child1 c=new child1(1,2,3,4);
}
}
MCQ
• Abstract class A has 4 virtual functions. Abstract class B defines only 2 of those
member functions as it extends class A. Class C extends class B and
implements the other two member functions of class A. Choose the correct
option below.
1. Program won’t run as all the methods are not defined by B
2. Program won’t run as C is not inheriting A directly
3. Program won’t run as multiple inheritance is used
4. Program runs correctly
MCQ
• Abstract class A has 4 virtual functions. Abstract class B defines only 2 of those
member functions as it extends class A. Class C extends class B and
implements the other two member functions of class A. Choose the correct
option below.
1. Program won’t run as all the methods are not defined by B
2. Program won’t run as C is not inheriting A directly
3. Program won’t run as multiple inheritance is used
4. Program runs correctly
Abstract Classes
Java allows abstract classes
use the modifier abstract on a class header to declare an abstract
class
abstract class Vehicle
{ … }
An abstract class is a placeholder in a class hierarchy that
represents a generic concept
Vehicle
75
Abstract Classes
An abstract class often contains abstract methods, though it
doesn’t have to
Abstract methods consist of only methods declarations, without any
method body
76
What is Abstract Class
77
Important Point About Abstract Class
78
Example
// Class 2
class Derived extends Base {
void fun()
{
System.out.println("Derived fun() called");
}
}
79
Cont..
// Class 3
// Main class
class Main {
// Main driver method
public static void main(String args[])
{
// We can have references of Base type.
Base b = new Derived();
b.fun();
}
}
80
Example
81
Cont..
class Main {
83
Example 3
abstract class Base {
// Demo method
void fun()
{
// Print message if class 1 function is called
System.out.println(
"Function of Base class is called");
}
}
84
Cont..
Class Derived extend Base {} //class 2
class Main {
// Main driver method
public static void main(String args[])
{
// Creating object of class 2
Derived d = new Derived();
// Calling function defined in class 1 inside main()
// with object of class 2 inside main() method
d.fun();
}
}
85
Abstract Classes Can Also Have final Methods
// Abstract method
static void demofun()
{
// Print statement
System.out.println("Geeks for Geeks");
}
88
}
Cont..
90
2
How to achieve or implement Abstraction in Java?
There are two ways to implement abstraction in java. They are as follows:
a) Abstract class (0 to 100%)
b) Interface (100%)
91
3
92
4
93
5
What is Abstract in Java?
Abstract is a non-access modifier in java that is applicable for classes, interfaces, methods, and inner classes.
94
6
What is Abstract method in Java?
A method which is declared with abstract modifier and has no implementation (means no body) is called abstract
method in java.
It does not contain any body. It has simply a signature declaration followed by a semicolon
95
7
96
8
Can an abstract method be declared with private modifier?
No, it cannot be private because the abstract method must be implemented in the child class. If we declare it as private,
we cannot implement it from outside the class.
97
9
98
10.
99
11
Is it possible to create an object of abstract class in Java?
No. It is not possible but we can create an object of its subclass.
10
12
Is it possible that an abstract class can have without any abstract method?
Yes
10
13,14,15
Can an abstract class have constructor?
Yes.
17. Is abstract class allow to define private, final, static, and concrete methods?
Yes.
18. Is it possible to achieve multiple inheritance through abstract class?
No.
10
16
Can we define an abstract method inside non-abstract class (concrete class)?
No, we cannot define an abstract method in non-abstract class.
10
17
10
18
10
19
Why abstract class has constructor even though you cannot
create object?
We cannot create an object of abstract class but we can create
an object of subclass of abstract class. When we create an
object of subclass of an abstract class, it calls the constructor of
subclass.
This subclass constructor has a super keyword in the first line
that calls constructor of an abstract class. Thus, the constructors
of an abstract class are used from constructor of its subclass.
If the abstract class doesn’t have constructor, a class that
extends that abstract class will not get compiled.
10
20
10
21
10
Single vs. Multiple Inheritance
109
Interface
11
Interface
An interface is a reference type in Java. It is
similar to class. It is a collection of abstract
methods.
An Interface in Java programming language is
defined as an abstract type used to specify the
behavior of a class. An interface in Java is a
blueprint of a class. A Java interface contains
static constants and abstract methods.
11
Interface
An interface is basically a kind of class.
Like classes, interfaces contain methods and
variables but with a major difference.
The difference is that interfaces define only
abstract methods and final fields.
This means that interfaces do not specify any code
to implement these methods and data fields
contain only constants.
Therefore, it is the responsibility of the class that
implements an interface to define the code for
implementation of these methods.
11
Cont..
11
Syntax
interface {
// declare constant fields
// declare methods that abstract // by default.
}
To declare an interface, use the interface keyword. It is used
to provide total abstraction. That means all the methods in an
interface are declared with an empty body and are public and
all fields are public, static, and final by default. A class that
implements an interface must implement all the methods
declared in the interface. To implement interface use
implements keyword.
11
Cont..
Why use interfaces when we have abstract classes?
The reason is, abstract classes may contain non-
final variables, whereas variables in the interface
are final, public and static.
11
Class Vs Interface
S. N. Class Interface
The access specifiers used with classes In Interface only one specifier is
3.
are private, protected, and public. used- Public.
11
Example
Interface animal
{
public void eat();
public void travel();
}
Save As animal.java
11
Cont..
Public class mint implements animal {
Public void eat() {
System.out.println(“Mammal eats”);
}
Public void travel() {
System.out.println(“Mammal travels”);
}
Public void nooflegs() {
return 0;
}
12
Cont..
public static void main(String args[]){
mint obj=new mint();
obj.eat();
obj.travel();
}
}
12
Advantages of Interfaces in Java
•Without bothering about the implementation part,
we can achieve the security of the
implementation.
•In Java, multiple inheritance is not allowed,
however, you can use an interface to make use of
it as you can implement more than one interface.
12
Important Points
While interfaces are allowed to extend to other interfaces, sub
interfaces cannot define the methods declared in the super
interfaces.
After all, sub interfaces are still interfaces, not classes.
Instead, it is the responsibility of any class that implements the
derived interface to define all the methods.
Note that when an interface extends two or more interfaces,
they are separated by commas.
It is important to remember that an interface cannot extend
classes. This would violate the rule that an interface can have
only abstract methods and constants.
12
Implementing Interfaces
Interfaces are used as super classes whose properties are
inherited by classes.
It is therefore necessary to create a class that inherits the given
interface. This is done as follows:
class class_name implements interface_name
{
body of class_name
}
12
Implementing Interfaces
Here the class class_name implements the interface
interface_name.
A more general form of implementation may look like this:
class class_name extends super_class implements
interface-1, interface-2,…….interface-n
{
body of class_name
}
12
Cont.
This shows that a class can extend another class while implementing
interfaces.
When a class implements more than one interface, they are separated
by comma.
Now, consider the following program.
Output:
Area of Rectangle = 190.65
Area of Circle = 490.625
Accessing Interface Variables
Interfaces can be used to declare a set of constants that can be used in
different classes.
The constant values will be available to any class that implements the
interface.
class Student
extends
extends implements
class Results
Example
class Student // Super class
{
int roll_no ;
void getNumber(int n)
{ roll_no = n ; }
void putNumber( )
{ System.out.println("\n Roll no: = " + roll_no); }
} // End of the super class
class Test extends Student // Sub class
{
float part1, part2 ;
void getMarks(float m1, float m2)
{ part1 = m1 ; part2 = m2 ; }
void putMarks( )
{
System.out.println(" Marks obtained" );
System.out.println(" Part1 = " + part1);
System.out.println(" Part2 = " + part2);
}
}
interface Sports
{
float sportWt = 6.0f ;
void putWt( );
}
class Results extends Test implements Sports
{
float total ;
public void putWt( )
{
System.out.println(" Sports Wt = " + sportWt);
}
void display( )
{
total = part1 + part2 + sportWt ;
putNumber( );
putMarks( );
putWt( );
System.out.println(" Total score = " + total);
}
}
class Hybrid
{
public static void main(String args[ ])
{
Results student1 = new Results( );
student1.getNumber(1234);
student1.getMarks(27.5f, 24.5f);
student1.display( );
}
}
Output:
Roll no: = 1234
Marks obtained
Part1 = 27.5
Part2 = 24.5
Sports Wt = 6.0
Total Score = 58.0
Dynamic Binding, using an interface
interface Shape
{
float PI=3.14F;
void displayArea();
}
class Circle implements Shape
{
private float radius ;
public Circle(float r)
{ radius = r; }
public void displayArea()
{ System.out.print(“\n Area of the Circle is: “ + (PI *radius*radius) ) ; }
}
class Rectangle implements Shape
{
private float length, breadth;
public Rectangle(float l, float b)
{ Length =l; breadth = b; }
public void displayArea()
{ System.out.print(“\n Area of rectangle = “ + (length*breadth) ) ; }
}
class ShapeRun
{
public static void main(String args[])
{
Shape s ;
Circle c = new Circle(5.5f);
s=c;
s.displayArea();
Rectangle r = new Rectangle(5.5f 3.5f) ;
s=r;
s.displayArea();
}
}
Output:
Abstract Class Interface
Abstract classes are used only when Interfaces can be implemented by
there is a “is-a” type of relationship classes that are not related to one
between the classes. another.
You cannot extend more than one You can implement more than one
abstract class. interface.
Abstract class can implemented some Interfaces can not implement methods.
methods also.
With abstract classes, you are grabbing With Interfaces, you are merely
away each class’s individuality. extending each class’s functionality.
An abstract class can have instance An Interface can only declare constants
methods that implement a default and instance methods, but cannot
behavior. implement default behavior and all
methods are implicitly abstract.
An abstract class is a class which may An interface has all public members
have the usual flavors of class members and no implementation.
(private, protected, etc.), but has some
abstract methods.
When to use the interface and an abstract class?
Interfaces are useful when you do not want classes to inherit
from unrelated classes just to get the required functionality.
➢An interface would be best choice for above case. Because you got
the method which got various implementations. So it's the key concept
if your methods got various implementations you should always go for
interface.
➢This is because when you define an object of the class Flat101 you will have
access to all the method and can any time tamper the implementation.
➢On the other hand if you get the interface object, you can only invoke the
method but not modify. Security can be achieved through interfaces
Interface Nesting
public interface outerinter{
void display();
interface Inner {
void Innermethod();
}
}
14
class fibo implements outerinter.Inner {
14
System.out.println("Printing from nested interface method");
}
public static void main(String args[])
{
outerinter.Inner obj= new fibo();
obj.Innermethod();
}
14
THANK YOU