12.4 new
- We can create String object by using new operator.
a). String name1 ;
name1 = new String(“Jeswanth”);
(or)
b). String name2 = new String(“Nireekshan”);
-------------------------------------------------------------------
Program : Creating String object by using new operator
Program name : StringDemo2.java
Output :
First name is : Prasad
Second name is : Kumar
class StringDemo2
{
public static void main(String args[])
{
String name1 ;
name1 =new String( “Prasad”);
String name2 = new String(“Kumar”);
System.out.println(“First name is:”+name1);
System.out.println(“Second name is:”+name2);
}
}
Compile : javac StringDemo2.java
Run : java StringDemo2
Output :
First name is : Prasad
Second name is : Kumar
-------------------------------------------------------------------
Thanks for your time.
Thanks for your time.
Nireekshan