1 / 4

CLASES ABSTRACTAS

CLASES ABSTRACTAS. DEFINICIÓN. Una clase abstracta es una clase que se introduce sólo para que se deriven nuevas clases de ella, no para que se creen objetos con su nombre. Del mismo modo, un método abstracto es un método que se introduce para que sea redefinido en una clase derivada.

Download Presentation

CLASES ABSTRACTAS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CLASES ABSTRACTAS

  2. DEFINICIÓN Una clase abstracta es una clase que se introduce sólo para que se deriven nuevas clases de ella, no para que se creen objetos con su nombre. Del mismo modo, un método abstracto es un método que se introduce para que sea redefinido en una clase derivada. abstract class GraphObj { int x, y; // La posición central GraphObj(int ix, int iy) { x= ix; y= iy; } // constructor void Move(int dx, int dy) { x+= dx; y+= dy; } abstract void Paint(Graphics g); // Paint es abstracto }

  3. Esta clase no se puede usar para crear un objeto, por lo que lo siguiente es un error: GraphObj gf= new GraphObj(10,20); // error La idea es que sólo se pueden crear objetos de clases derivadas de la clase anterior: class Line extends GraphObj { // x e y se heredan int ix, iy; GraphObj(int aix, int aiy, int afx, int afy) { super((aix+afx)/2, (aiy+afy)/2); ix= aix; iy= aiy; } void Paint(Graphics g) { g.DrawLine(xi,yi,x+(x-xi),y+(y-yi)); } // Move se hereda de GraphObj }

More Related