Home » Java programming language

Java SimpleTimeZone clone() Method with Example

SimpleTimeZone Class clone() method: Here, we are going to learn about the clone() method of SimpleTimeZone Class with its syntax and example.
Submitted by Preeti Jain, on March 12, 2020

SimpleTimeZone Class clone() method

  • clone() method is available in java.util package.
  • clone() method is used to return a shallow copy of this SimpleTimeZone instance.
  • clone() method is a non-static method, it is accessible with the class object and if we try to access the method with the class name then we will get an error.
  • clone() method does not throw an exception at the time of cloning an object.

Syntax:

    public Object clone();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of the method is Object, it returns cloned copy of this SimpleTimeZone.

Example:

// Java program to demonstrate the example 
// of Object clone() method of SimpleTimeZone

import java.util.*;

public class CloneOfSimpleTimeZone {
    public static void main(String args[]) {
        // Instantiate SimpleTimeZone object
        TimeZone s_tz = SimpleTimeZone.getDefault();
        System.out.println("s_tz: " + s_tz);

        // By using clone() method is to
        // return shallow copy of this
        // simpletimezone s_tz

        Object stz_clone = s_tz.clone();
        System.out.println("s_tz.clone(): " + stz_clone);
    }
}

Output

s_tz: sun.util.calendar.ZoneInfo[id="GMT",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]
s_tz.clone(): sun.util.calendar.ZoneInfo[id="GMT",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.