Use packages to implement two classes both named Account one

Use packages to implement two classes both named Account: one should represent bank accounts, the other should represent computer user accounts. Write a main method in another class (in the default package) that creates and prints an instance of each class. Hint: You can’t import two classes with the same name, but there is another way to refer to classes in other packages. Second hint: look up “fully qualified name” in the Java

Solution

Account.java

package org.bankaccounts;

public class Account {
   //Default Account Object created
   public Account()
   {
       System.out.println(\"::Created Bank Account Obejct ::\");
   }

   //toString() method is used to display the contents inside the class
   @Override
   public String toString() {
       return \"*** This is the content inside the Bank Account ***\ \";
   }
  

}

________________________________________

Account.java

package org.computer.useraccount;

public class Account {
   //Default Constructor
   public Account()
   {
       System.out.println(\"::Created Computer Account Obejct ::\");
   }

   //toString() method is used to display the contents inside the class
   @Override
   public String toString() {
       return \"---This is the content inside the Computer User Account---\ \";
   }
  
}

_______________________________________

MainClass.java

import org.bankaccounts.Account;


public class MainClass {

   public static void main(String[] args) {
       //Creating an object for Bank Account Object
       org.bankaccounts.Account bankAccount=new org.bankaccounts.Account();
      
       //Calling the toString() method on bankAccount Object
       System.out.println(bankAccount.toString());
      
       //Creating an object for Computer user Account Object
       org.computer.useraccount.Account compAccount=new org.computer.useraccount.Account();
      
       //Calling the toString() method on Computer account Object
       System.out.println(compAccount.toString());
   }

}

______________________________________

Output:

::Created Bank Account Obejct ::
*** This is the content inside the Bank Account ***

::Created Computer Account Obejct ::
---This is the content inside the Computer User Account---

__________________________Thank You

Use packages to implement two classes both named Account: one should represent bank accounts, the other should represent computer user accounts. Write a main me
Use packages to implement two classes both named Account: one should represent bank accounts, the other should represent computer user accounts. Write a main me

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site