Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Parameterized Constructor

class Main {

  String fruits;

  // constructor accepting single value
  Main(String fruit) {
    fruits = fruit;
    System.out.println("Fruit " + fruits);
  }

  public static void main(String[] args) {

    // call constructor by passing a single value
    Main obj1 = new Main("Banana");
    Main obj2 = new Main("Apple");
    Main obj3 = new Main("Mango");
  }
}
Source by softhunt.net #
 
PREVIOUS NEXT
Tagged: #Parameterized #Constructor
ADD COMMENT
Topic
Name
9+4 =