Hello friends...
The String class supports several constructors. To create an empty String, you call the default constructor.
For example,
String s = new String();Thank you
If you want CA CPT coaching in Tamil nadu kindly visit our website ksacademy
Chat with our AI personalities
The Exception class has 4 constructors. They are: a. Exception() b. Exception(String arg) c. Exception(String arg, Throwable arg1) d. Exception(Throwable arg)
The String class has multiple Constructors. Some of them are: 1. String - new String(String val) 2. Character Array - new String(char[] array) 3. Character Array with index positions - new String(char[] array. int start, int end)
As of Java 1.6 it has 3: StringTokenizer(String str) StringTokenizer(String str, String delim) StringTokenizer(String str, String delim, boolean returnDelims)
Constructors have the same identifier as that of the class, so if the name of your class is Book then your constructor must also be named Book. Constructors have no return type, not even void.
There are three constructors that can be used to create a File class.public File(String path). 'path' is basically the full pathname to the file in your current directory.public File(String path, String name). You can also separate the path and filename. 'name' would represent the filename and 'path' would represent the name of the directory.public File(File directory, String name). This is somehow similar to the previous way; however, directory is a File object rather than a String object.To create a new File object:File newFile = new File("something");