Respuesta :
Answer:
public Clock(Clock a) // Copy constructor
{
hour = a.hour;
Ticking = a.Ticking;
}
Explanation:
Following are the program in c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Program
{
class Clock // Class
{
// variables For Clock Class
private int hour;
private bool Ticking;
public Clock(int hour, bool ticking) // Parameterized constructor for Initilizing
{
this.hour = hour;
this.Ticking = ticking;
}
public Clock(Clock a) // Copy constructor
{
hour = a.hour;
Ticking = a.Ticking;
}
static void Main(string[] args) // Main function
{
// Create a new object For Clock Class.
Clock c1 = new Clock(20, true);
// c1 are copied to c2.
Clock c2 = new Clock(c1);
Console.WriteLine("Hours : " + c2.hour);
Console.WriteLine("Ticking : " + c2.Ticking);
Console.Read();
}
}
}
Output:
Hour : 20
Ticking : True
In this program their is a single class Clock which have a variable hours and ticking. hour is of type integer and ticking is type of bool which is either True or False. Here two types of constructor are used:-
1. Parameterized Constructor : This is used to initialize the value to a variables declared in Clock Class. Like in program when c1 object is created it automatically initialize the value to variable of class.
2. Copy Constructor : This constructor is used to copy the c1 instance to the c2 instance.
Hence, c1 instance have value Hour And Ticking is copied to c2 instance. So c2 also have the same value like c1 instance have