Code to create a java class and its object instances
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Factory{ | |
private String SolidFood1; // Solid Food 1st Instance Variable | |
private String SolidFood2; // Solid Food 2nd Instance Variable | |
private String LiquidFood1; // Liquid Food 3rd Instance Variable | |
public Factory(){} // 0-arg constructor (Not used) | |
public Factory(String sf1, String sf2, String lf1){ // 3-arg constructor | |
SolidFood1 = sf1; | |
SolidFood2 = sf2; | |
LiquidFood1 = lf1; | |
} | |
public String getSF1(){return SolidFood1;} // Method to get the name of 1st Instance Variable | |
public String getSF2(){return SolidFood2;} // Method to get the name of 2nd Instance Variable | |
public String getLF1(){return LiquidFood1;} // Method to get the name of 3rd Instance Variable | |
public static void main(String[] args){ // Main Method - Only this method gets executed | |
Factory lunchBox = new Factory("s1","s2", "l1"); // Object Created Yay!!! | |
System.out.println("Solid Food 1 is = " + lunchBox.getSF1()); // Call the methods to get the names and print them | |
System.out.println("Liquid Food 1 is = "+ lunchBox.getLF1()); | |
System.out.println("Solid Food 2 is = "+ lunchBox.getSF2()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment