Question
Write java programs to demonstrate use of abstract class and interface. Make necessary assumptions.
Answer :
Word Count : 812
___ ________ ____ ___ _______ _______ ______ ________.
__________ ____ __________ _____ ______ _____.
________ _____ _______ ____ _______ _______ ___ __________ ___ _____ ______ _________.
______ ______ _________ _________ ________.
___ ________ ______ ____ _________ ______ ____ _____ _______ ___ ____ __________.
______ _________ _______ ____ _____ _______ ____ _______ _______ _________.
_______ __________ ______ ________ ____ _________ ____ _______ _________ ___.
____ ______ ______ _________ _____.
__________ ___ __________ ________ _____ ______ _____ ________ _____.
_______ ______ _________ _________ ________ ________ _____ ___ ______ ______ ________.
________ _____ __________ _____ ____ ________ _____.
______ ____ ___ _________ ____ ___ __________ _________ _________ ______.
_________ _______ ________ _______ ______ _______.
_______ _________ __________ ________ ___ ______ _____ ___.
___ ________ ______ __________ _________ ___.
_______ ________ ___ __________ _________.
_____ ___ _____ _________ ______ ______.
_________ __________ _____ _______ _____ __________ _______ ______ __________ __________.
__________ ________ __________ ________ _______ ________.
____ _____ _____ __________ __________ __________ ________.
_______ _______ __________ ___ __________ _____ _____ ___.
______ ____ _______ ______ _________ _______ __________ ___.
_______ _____ __________ ___ _____ ____ _______ ___ __________ ________ ______.
_____ __________ ___ _______ ___ ____ _____ _______ ________ _____ ______.
__________ ___ ____ ____ _________.
____ __________ __________ ______ _____ __________.
______ ____ ________ _______ __________.
__________ __________ ____ __________ _______ ______ _________ ___ _______ _____ _____ _______.
_______ __________ ____ ____ ________ ______ ________ ________ ________ __________ _________.
______ ______ _______ __________ ________ ______ ______ _______ ___.
_______ ___ ______ ____ ____ _________ _______ ___.
_________ _______ _________ ______ ________ _______ _______ ________ ____ _______ ___ ___.
______ ____ ___ ___ ____.
__________ _________ ____ _________ ______ _______ ____ ___ ______.
______ _______ _____ ________ _________ ____ ____ __________ ________ _____ ___.
_________ ________ _________ ___ ______ __________ __________ ___ ________ ___.
___ _______ _______ _____ ____.
____ _________ ___ ___ _______ ____.
__________ _______ ________ ________ ___ ________ _____ ____ ___.
_______ ________ _________ ____ ______ _________ _________ ___ ___ _________.
____ __________ ____ ________ _____ _______ ___ ______ ____ ___ ___ _______.
_____ __________ ____ ___ ________ _________ __________ ___ ________ ______.
__________ __________ _____ ______ ___ _______ _______ _____ ________ ____ _____.
__________ __________ _________ ______ ___.
_______ _____ __________ ___ ____ ________ _________ _____ ____ ____ ______ _____.
_______ _______ ____ ____ ______ ______ _________ _____ __________ ______ ____ _____.
_______ ______ ______ _________ __________ ________ ___.
_______ ________ _________ _________ _______ ____ ____ _______ _______ ____ __________.
_________ ____ ____ ________ _____ _____ _______ __________ ___.
___ ____ ______ _________ ______ _________ _____ _______ ______ ___ _________ _________.
_____ ____ _______ _____ ____ _____ _________ _________ ___ _______ _________ _______.
_______ _________ _________ ______ _______ _________ __________ _____ ________ ___ ______ ____.
______ ___ ______ __________ ____ ________ ______ _________ __________ ___.
_________ __________ ___ _____ __________ _________ ____ ________ __________ ___ __________ ____.
___ __________ ____ _____ ______ ___ ___ _____.
______ ___.
Skip in 10
Object Oriented Programming in Java emphasizes abstraction, encapsulation, inheritance, and polymorphism. Among these principles, abstraction plays a vital role in reducing complexity by hiding implementation details and exposing only essential features. In Java, abstraction can be achieved through abstract classes and interfaces. An abstract class allows partial abstraction by including both abstract and concrete methods, while an interface provides complete abstraction by defining method signatures without implementation. The following Java programs demonstrate the use of abstract class and interface with necessary assumptions. An abstract class is declared using the keyword abstract. It cannot be instantiated directly and may contain abstract methods (without body) as well as concrete methods (with body). Abstract classes are useful when different subclasses share common behavior but also require specific implementations of certain methods. Consider a scenario of a banking system in which different types of accounts calculate interest differently. We assume that all accounts have an account number and balance, and each type of account must implement its own method to calculate interest. The following program demonstrates the use of an abstract class: ```java abstract class BankAccount { protected int accountNumber; protected double balance; public BankAccount(int accountNumber, double balance) { this.accountNumber = accountNumber; this.balance = balance; } public void deposit(double amount) { balance += amount; System.out.println("Amount deposited: " + amount); } public void displayBalance() { System.out.println("Account Number: " + accountNumber); System.out.println("Current Balance: " + balance); } public abstract double calculateInterest(); } class SavingsAccount extends BankAccount { private double interestRate = 0.04; public SavingsAccount(int accountNumber, double balance) { super(accountNumber, balance); } public double calculateInterest() { return balance * interestRate; } } class CurrentAccount extends BankAccount { private double interestRate = 0.02; public CurrentAccount(int accountNumber, double balance) { super(accountNumber, balance); } public double calculateInterest() { return balance * interestRate; } } public class AbstractClassDemo { public static void main(String[] args) { BankAccount savings = new SavingsAccount(101, 10000); BankAccount current = new CurrentAccount(102, 15000); savings.deposit(2000);
___ _______ ______ ______ ________ ________ ____ _____.___ ________ ____ ___ _______ _______ ______ ________.
__________ ____ __________ _____ ______ _____.
________ _____ _______ ____ _______ _______ ___ __________ ___ _____ ______ _________.
______ ______ _________ _________ ________.
___ ________ ______ ____ _________ ______ ____ _____ _______ ___ ____ __________.
______ _________ _______ ____ _____ _______ ____ _______ _______ _________.
_______ __________ ______ ________ ____ _________ ____ _______ _________ ___.
____ ______ ______ _________ _____.
__________ ___ __________ ________ _____ ______ _____ ________ _____.
_______ ______ _________ _________ ________ ________ _____ ___ ______ ______ ________.
________ _____ __________ _____ ____ ________ _____.
______ ____ ___ _________ ____ ___ __________ _________ _________ ______.
_________ _______ ________ _______ ______ _______.
_______ _________ __________ ________ ___ ______ _____ ___.
___ ________ ______ __________ _________ ___.
_______ ________ ___ __________ _________.
_____ ___ _____ _________ ______ ______.
_________ __________ _____ _______ _____ __________ _______ ______ __________ __________.
__________ ________ __________ ________ _______ ________.
____ _____ _____ __________ __________ __________ ________.
_______ _______ __________ ___ __________ _____ _____ ___.
______ ____ _______ ______ _________ _______ __________ ___.
_______ _____ __________ ___ _____ ____ _______ ___ __________ ________ ______.
_____ __________ ___ _______ ___ ____ _____ _______ ________ _____ ______.
__________ ___ ____ ____ _________.
____ __________ __________ ______ _____ __________.
______ ____ ________ _______ __________.
__________ __________ ____ __________ _______ ______ _________ ___ _______ _____ _____ _______.
_______ __________ ____ ____ ________ ______ ________ ________ ________ __________ _________.
______ ______ _______ __________ ________ ______ ______ _______ ___.
_______ ___ ______ ____ ____ _________ _______ ___.
_________ _______ _________ ______ ________ _______ _______ ________ ____ _______ ___ ___.
______ ____ ___ ___ ____.
__________ _________ ____ _________ ______ _______ ____ ___ ______.
______ _______ _____ ________ _________ ____ ____ __________ ________ _____ ___.
_________ ________ _________ ___ ______ __________ __________ ___ ________ ___.
___ _______ _______ _____ ____.
____ _________ ___ ___ _______ ____.
__________ _______ ________ ________ ___ ________ _____ ____ ___.
_______ ________ _________ ____ ______ _________ _________ ___ ___ _________.
____ __________ ____ ________ _____ _______ ___ ______ ____ ___ ___ _______.
_____ __________ ____ ___ ________ _________ __________ ___ ________ ______.
__________ __________ _____ ______ ___ _______ _______ _____ ________ ____ _____.
__________ __________ _________ ______ ___.
_______ _____ __________ ___ ____ ________ _________ _____ ____ ____ ______ _____.
_______ _______ ____ ____ ______ ______ _________ _____ __________ ______ ____ _____.
_______ ______ ______ _________ __________ ________ ___.
_______ ________ _________ _________ _______ ____ ____ _______ _______ ____ __________.
_________ ____ ____ ________ _____ _____ _______ __________ ___.
___ ____ ______ _________ ______ _________ _____ _______ ______ ___ _________ _________.
_____ ____ _______ _____ ____ _____ _________ _________ ___ _______ _________ _______.
_______ _________ _________ ______ _______ _________ __________ _____ ________ ___ ______ ____.
______ ___ ______ __________ ____ ________ ______ _________ __________ ___.
_________ __________ ___ _____ __________ _________ ____ ________ __________ ___ __________ ____.
___ __________ ____ _____ ______ ___ ___ _____.
______ ___.
IGNOU ACADEMY
Your IGNOU journey, made easier.
- Solved Assignments
- Study Notes
- Guess Papers
- Question Papers
Continue Reading — It's Free
Sign in with Google to unlock more of this answer.
✓ Free access
✓ Unlock up to 60% of the answer
✓ No payment required
✓ Unlock up to 60% of the answer
✓ No payment required
Quick Google sign-in. No separate registration form.