daily pastebin goal
14%
SHARE
TWEET

Untitled

a guest Jul 17th, 2018 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4.  
  5. public class JavaMainClass {
  6.  
  7.     private static String className;
  8.     private static EmployeeInterface interfaceObj;
  9.    
  10.     public static void main (String args[]) throws IOException {
  11.        
  12.         /******************************************* INTERFACE RUN IN JAVA ***************************************** START ********((*********/
  13.         //Input child class name to extend (Input ContractorClass , as that is the only class implementing the EmployeeInterface for now)
  14.         System.out.println("Please enter the class name to instantiate: ");
  15.         className = br.readLine();
  16.        
  17.         System.out.print("The class name enetered is: ");
  18.         System.out.println(className);
  19.        
  20.         //instantiate the child class entered by user
  21.         try {
  22.             //Instantiate the child class
  23.             //obj = new AbstractClassChild1();
  24.             interfaceObj = (EmployeeInterface) Class.forName(className).newInstance();
  25.             interfaceObj.permSalary();
  26.             interfaceObj.contractorSalary();
  27.            
  28.             //Call constructor of child class (it does not get called by newinstance(). Contructors can even have params below
  29.             try {
  30.                 Class.forName(className).getConstructor();
  31.             } catch (NoSuchMethodException e) {
  32.                 e.printStackTrace();
  33.             } catch (SecurityException e) {
  34.                 e.printStackTrace();
  35.             }
  36.  
  37.         } catch (InstantiationException e) {
  38.             e.printStackTrace();
  39.         } catch (IllegalAccessException e) {
  40.             e.printStackTrace();
  41.         } catch (ClassNotFoundException e) {
  42.             e.printStackTrace();
  43.         }
  44.        
  45.         /******************************************* INTERFACE CLASS RUN IN JAVA ***************************************** END ****************/
  46.     }
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top