NAME – ISHAAN SINGH CHAUHAN
CLASS – 2BCA B
REG NO - 24215118
Java Lab Prog 6 (Package & Interface)
Task - 1
Create two packages(pack1 and pack2) and
call pack1 with the associated class under
pack2 to display bank account detail like
Account number, customer name, phone no. ,
balance.
CODE:
package ASSIGNMENTS;
public class BankAccount {
private String accountNumber;
private String customerName;
private String phoneNo;
private double balance;
public BankAccount(String accountNumber, String customerName, String phoneNo,
double balance) {
this.accountNumber = accountNumber;
this.customerName = customerName;
this.phoneNo = phoneNo;
this.balance = balance;
}
public String getAccountNumber() {
return accountNumber;
public String getCustomerName() {
return customerName;
public String getPhoneNo() {
return phoneNo;
public double getBalance() {
return balance;
public void displayAccountDetails() {
System.out.println("Account Number: " + getAccountNumber());
System.out.println("Customer Name: " + getCustomerName());
System.out.println("Phone Number: " + getPhoneNo());
System.out.println("Balance: $" + getBalance());
package ASSIGNMENTS;
import ASSIGNMENTS.BankAccount;
public class AccountDetails {
public static void main(String[] args) {
BankAccount account = new BankAccount("24215118", "IAN ", "8130606417",
500000);
account.displayAccountDetails();
OUTPUT:
Task-2
Define two interfaces Vehicle and Air_ Vehicle, each with a single
method
drive() and fly() respectively.
The Aeroplan class implements both interfaces Vehicle and Air_
Vehicle.
Create an instance of Aeroplan and call both drive() and fly()
methods and
demonstrate how a class can implement multiple interfaces in Java.
CODE:
package ASSIGNMENTS;
public interface Vehicle {
void drive();
package ASSIGNMENTS;
public interface AirVehicle {
void fly();
package ASSIGNMENTS;
public class Aeroplane implements Vehicle, AirVehicle {
public void drive() {
System.out.println("The Aeroplan is driving on the ground.");
}
public void fly() {
System.out.println("The Aeroplan is flying in the air.");
package ASSIGNMENTS;
public class Main {
public static void main(String[] args) {
Aeroplane aeroplane = new Aeroplane();
aeroplane.drive();
aeroplane.fly();
OUTPUT: