0% found this document useful (0 votes)
4 views

Practical No 6 Interface

Uploaded by

Shikha Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Practical No 6 Interface

Uploaded by

Shikha Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Practical No 6

(Interface and Packages)


(Interface)
1. Write a Program in Java to create an Interface animal, with methods eat () and
move (). Define a class Cat and Dog, which implements the animal Interface.
2. Declare an interface called function that has a method named evaluate () that takes
an arbitrary integer value as a parameter and returns an integer value.
Create a class Half that implements function. Make the implementation of method
evaluate. Return the value obtained by dividing the integer value by 2.
Create a class Double that implements function. Make the implementation of
method evaluate. Return the value obtained by multiplying the integer value by 2
3. Define an interface Shape containing function area. Define two classes Triangle and
Rectangle that implement Shape interface with proper code for calculation of area.
(Packages)

4. Q1) Write a program to define a user defined package Mypack in which you will write a
class Balance. The Balance will have data members as String Name, Double Balance.
Write a constructor to initialize the member. Write a function to display Name and
Balance. Now import this package in your class.
5. Q2) Create a package Animals. In package Animals create interface Animal with suitable
behaviors (move, eat). Define two classes Dog and Cat that implement Animals interface.
Now import this package in your class.
6. Q3) Define a package “Diagram” which contain the following:
7. Define an interface Shape containing function area. Define two classes Triangle and
Rectangle that implement Shape interface with proper code for calculation of area. Also
define a class to test the above and call the function area using variable of Shape.

You might also like