Searching on java api document, i found that the getScreenSize() method is an abstract method in the Toolkit class. Now i'm wondering why the code below works.
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
setLocation((d.width - getWidth())/2,(d.height - getHeight())/2);
if getScreenSize() is abstract, then we shouldn't be able to use it. How does it work?
Toolkit.getDefaultToolkit
will return a subclass of Toolkit
which implements getScreenSize()
appropriately. It's defined as abstract in Toolkit
so that the behavior can be defined separately for different platforms.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments