Skip to content

Instantly share code, notes, and snippets.

@jayanthrbharadwaj
Last active June 4, 2019 19:40
Show Gist options
  • Save jayanthrbharadwaj/afecefb8c6298cd5c80f9b8af4d7202d to your computer and use it in GitHub Desktop.
Save jayanthrbharadwaj/afecefb8c6298cd5c80f9b8af4d7202d to your computer and use it in GitHub Desktop.
Nested Class
package nesting;
public class Father {
/* ============================================================
methods in the class Father can access PRIVATE
members of this NESTED class !!!
============================================================ */
private class BankAccount {
private double accountNumber; // *** Private variable !!! ***
private String transferee; // *** Private variable !!! ***
public BankAccount (double x) {
accountNumber = x;
transferee = null; // It's good to make next to point to illegal null
}
}
private BankAccount bankAccount; // **** Access SHOULD be set to private ****
// Constructor
public Father () {
bankAccount = null; // Make an empty list
}
/* ====================================================
put( x ): store value x into the list
==================================================== */
public void put (double x, String name) {
BankAccount e;
e = new BankAccount(x);
e.transferee = name; // You can use PRIVATE variables in BankAccount !
// Store this in a server DB or pass it over REST
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment