Respuesta :
Answer:
public Mysring(char[] Original)
{
int size= Original.length();
for(int i=0;i<=size;i++)
{
arr[i]=Original[i];
}
}
Public Mystring(String Original)
{
char[] arr=String.toCharArray();
}
Public Mystring(Mystring Original)
{
Int len=Original.arr.length();
for(int i=0;i<=len;i++)
{
arr[i]=Orginal.arr[i];
}
}
public int length()
{
Int len=arr.length();
return len;
}
Public char charAt(int index)
{
try
{
System.out.println(arr[index]);
}
catch(IndexOutOfBoundsException ex)
{
throw ex;
}
}
}
Explanation:
1) The first one is the Parameterized constructor. It takes an array of character as input, and assigns it to the array of character which is a field in the given class MyString.
2) The second one is also the Parameterized constructor, and it takes a string as input, and converts it to an array of characters, and finally assigns it to the character type field of the class MyString.
3) The third one is the copy constructor, and takes a previous object of the class as input, and assigns its values to the new instance of the class.
4) The fourth function returns the length of the character field of the class MyString.
5) The fifth function returns the character in the character field at the given index. And if Index is more than the length of the arr field, it through the IndexOutOfBoundsException.