Professional Documents
Culture Documents
Q1) Define an interface “Operation” which has method volume( ).Define a constant PI
having a value
3.142 Create a class cylinder which implements this interface (members –
radius,height). Create one object and calculate the volume.
SOLUTION:
import java.util.Scanner;
interface Operation {
double volume();
}
@Override
public double volume() {
return PI * radius * radius * height;
}
}
Q2) Write a program to accept the username and password from user if username and
password are not same then raise "Invalid Password" with appropriate msg.
SOLUTION:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);