Search
 
SCRIPT & CODE EXAMPLE
 

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");
  }
}
Comment

PREVIOUS NEXT
Code Example
Java :: diamond star pattern in java 
Java :: convert fileinputstream to string java 
Java :: blurview android github 
Java :: java throw keyword 
Java :: set textView.android:drawableEnd programmatically 
Java :: encapsulation in oop 
Java :: bukkit java get player count 
Java :: java for loop increment by 3 
Java :: jbutton border size java 
Java :: spring filter exception handling 
Java :: string to int in java 
Java :: java regex case insensitive 
Java :: how to go to next iteration of while loop java 
Java :: hollow pyramid star pattern in java 
Java :: Java char data type 
Java :: java class jar determine 
Java :: how to scan as a letter in java 
Java :: java map string to list 
Java :: does constructor return any value java 
Java :: palindrome java 
Java :: maven set java version 
Java :: how to check number format exception in java 
Java :: advantages of exception handling in java 
Java :: export JAVA_HOME=` mac 
Java :: logging in java 
Java :: what is var in java 
Java :: Java Looping Through Array Elements 
Java :: $JAVA_HOME ENV 
Java :: how to check if a person presses a button in jframe in java 
Java :: if else statement 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =