package Package.IO.Java.AIT; class BankAccount{ // data members private long accountNumber; private double balance; // initializing the data members using the constructor. public BankAccount(long accountNumber, double balance) { super(); this.accountNumber = accountNumber; this.balance = balance; } // total number of constructors are here: // two // one is: default constructor should be added by the compiler // another one is: parameterized constructor which we have created public long getAccountNumber() { return accountNumber; } public double getBalance() { return balance; } public double calculateInterest() { return balance * 0.05; } public void display() { System.out.println("Account Number of the user = "+accountNumber); System.out.println("Balance of the user account = "+balance); } } class SavingsAccount extends BankAccount{ public SavingsAccount(long accountNumber, double balance) { super(accountNumber, balance); } // @Override // public double calculateInterest() // { // return getBalance() * 0.15; // // extending the scope of private data member from parent class to child class is usually not // // possible. // // but if we can call that private data member using getter method, we can do it. // } @Override public double calculateInterest() { return getBalance() * 0.15; } } class CurrentAccount extends BankAccount{ public CurrentAccount(long accountNumber, double balance) { super(accountNumber, balance); } @Override public double calculateInterest() { return getBalance() * 0.25; } } public class MainClass { public static void main(String[] args) { SavingsAccount sa = new SavingsAccount(573602010007620l,15000.0); System.out.println("The Savings Account User Credentials are = "); sa.display(); System.out.println("The Rate of Interest for Savings Account Holder = "+sa.calculateInterest()); System.out.println("============================"); CurrentAccount ca = new CurrentAccount(1928374650l,25000.0); System.out.println("The Current Account User Credentials = "); ca.display(); System.out.println("The Rate of Interest for Current Account Holder = "+ca.calculateInterest()); } } ==================================================== class Day{ void greetings() { SOP("Good Morning"); } } class Afternoon extends Day{ void greetings() { SOP("Good Afternoon"); } } class Evening extends Day{ void greetings() { SOP("Good Evening"); } } ==================================== class A{ // compiler can add default constructor public A() { } public A(int x) { } } ================================================ Q: How Overloading as static polymorphism/compile time polymorphism? ===================================================================== package Package.IO.Java.AIT; class ClassA{ public void m1() { System.out.println("Hello"); } public void m1(String name) { System.out.println("Hello "+name); } } public class Main { public static void main(String[] args) { ClassA ca = new ClassA(); ca.m1(); ca.m1("Ravi"); } } ========================================== How the overriding as run time polymorphism? ============================================== package Package.IO.Java.AIT; class ClassA{ public void m1() { System.out.println("Hello"); } } class ClassB extends ClassA{ @Override public void m1() { System.out.println("Hello"); System.out.println("Welcome To Ashok IT."); } } public class Main { public static void main(String[] args) { ClassB cb = new ClassB(); cb.m1(); ClassA ca = new ClassA(); ca.m1(); } } ============================================= char ch = 'a'; int i = 100; class A{ private int a; private float b; private Boolean c; } class Employee{ String name; int id; String designation; double salary; } class Student{ String name; int roll; char grade; int percentage; String locality; }