0% found this document useful (0 votes)
78 views5 pages

Java Lab Prog 6-24215118

Uploaded by

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

Java Lab Prog 6-24215118

Uploaded by

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

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:

You might also like