StringWriter getClass() method in Java with Examples
Last Updated :
21 Jun, 2019
The getClass() method of StringWriter Class in Java is used to get the parent Class of this StringWriter instance. This method does not accepts any parameter and returns the required Class details.
Syntax:
public final Class String getClass()
Parameters: This method accepts does not accepts any parameter.
Return Value: This method returns the Class details which is the parent Class of the StringWriter instance.
Below methods illustrates the working of getClass() method:
Program 1:
import java.io.*;
class GFG {
public static void main(String[] args)
{
try {
StringWriter writer
= new StringWriter();
String string = "GeeksForGeeks" ;
writer.write(string);
System.out.println( "Parent Class: "
+ writer.getClass());
}
catch (Exception e) {
System.out.println(e);
}
}
}
|
Output:
Parent Class: class java.io.StringWriter
Program 2:
import java.io.*;
class GFG {
public static void main(String[] args)
{
try {
StringWriter writer
= new StringWriter();
String string = "GFG" ;
writer.write(string);
System.out.println( "Parent Class: "
+ writer.getClass());
}
catch (Exception e) {
System.out.println(e);
}
}
}
|
Output:
Parent Class: class java.io.StringWriter
Share your thoughts in the comments
Please Login to comment...