Bom dia colegas.
Sou mais um mero aprendiz de java, e venho aqui explicitar a minha seguinte duvida.
Eis a minha classe programa.
namespace Classes
{
class Program
{
static void DoWork()
{
Pointx origin = new Pointx();
Pointx bottomRight = new Pointx(1024, 1280);
double distance = origin.DistanceTo(bottomRight);
Console.WriteLine("Distance is: {0}", distance);
Console.WriteLine("No of Point objects: {0}", Pointx.ObjectCount());
}
static void Main(string[] args)
{
try
{
DoWork();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
E a minha classe Pointx.
namespace Classes
{
class Pointx
{
private static int objectCount = 0;
private int x, y;
public static int ObjectCount()
{
return objectCount;
}
public Pointx()
{
//Console.WriteLine("Default constructor called");
this.x = -1;
this.y = -1;
objectCount++;
}
public Pointx(int x, int y)
{
//Console.WriteLine("x:{0}, y:{1}", x, y);
this.x = x;
this.y = y;
objectCount++;
}
public double DistanceTo(Pointx other)
{
int xDiff = other.x;
int yDiff = other.y;
return Math.Sqrt((xDiff * yDiff) + (yDiff * yDiff));
}
}
}
Eis as minhas duvidas, a quem puder responde-las, ficarei agradecido.
1 - aqui estou chamando um construtor para origin que esta declarado como Pointx
E como que nesta linha eu consigo invocar o DistanceTo com o origin sendo que ele recebeu o meu construtor Pointx() que é um método implementado na classe Pointx??? Deu pra entender a questão?
Obrigado a quem puder me ajudar.