<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FClass_Definition%2FInterface</id>
		<title>Java Tutorial/Class Definition/Interface - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://jexp.ru/index.php?action=history&amp;feed=atom&amp;title=Java_Tutorial%2FClass_Definition%2FInterface"/>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_Tutorial/Class_Definition/Interface&amp;action=history"/>
		<updated>2026-04-07T14:03:31Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://jexp.ru/index.php?title=Java_Tutorial/Class_Definition/Interface&amp;diff=4218&amp;oldid=prev</id>
		<title>Admin: 1 версия</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_Tutorial/Class_Definition/Interface&amp;diff=4218&amp;oldid=prev"/>
				<updated>2010-06-01T05:00:49Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 05:00, 1 июня 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://jexp.ru/index.php?title=Java_Tutorial/Class_Definition/Interface&amp;diff=4217&amp;oldid=prev</id>
		<title> в 17:44, 31 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://jexp.ru/index.php?title=Java_Tutorial/Class_Definition/Interface&amp;diff=4217&amp;oldid=prev"/>
				<updated>2010-05-31T17:44:27Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==  A Partial Interface Implementation ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
interface Conversions {&lt;br /&gt;
  double INCH_TO_MM = 25.4;&lt;br /&gt;
  double OUNCE_TO_GRAM = 28.349523125;&lt;br /&gt;
  double POUND_TO_GRAM = 453.5924;&lt;br /&gt;
  double HP_TO_WATT = 745.7;&lt;br /&gt;
  double WATT_TO_HP = 1.0 / HP_TO_WATT;&lt;br /&gt;
  public double inchesToMillimeters(double inches);&lt;br /&gt;
  public double ouncesToGrams(double ounces);&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Encapsulating Constants in a Program ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
interface ConversionFactors {&lt;br /&gt;
  double INCH_TO_MM = 25.4;&lt;br /&gt;
  double OUNCE_TO_GRAM = 28.349523125;&lt;br /&gt;
  double POUND_TO_GRAM = 453.5924;&lt;br /&gt;
  double HP_TO_WATT = 745.7;&lt;br /&gt;
  double WATT_TO_HP = 1.0 / HP_TO_WATT;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;25.4&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Extending Interfaces ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
interface ConversionFactors {&lt;br /&gt;
  double INCH_TO_MM = 25.4;&lt;br /&gt;
}&lt;br /&gt;
interface Conversions extends ConversionFactors {&lt;br /&gt;
  double inchesToMillimeters(double inches);&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Fields and Methods in an Interface ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;OL&amp;gt;&amp;lt;LI&amp;gt;Fields in an interface must be initialized and are implicitly public, static, and final.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;You declare methods in an interface just as you would in a class.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;Methods in an interface do not have a body.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;All methods are implicitly public and abstract&amp;lt;/LI&amp;gt;&amp;lt;/OL&amp;gt;&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
interface Conversions{&lt;br /&gt;
  double inchesToMillimeters(double inches);&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Initializing interface fields with non-constant initializers ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
import java.util.Random;&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    System.out.println(RandVals.randomInt);&lt;br /&gt;
    System.out.println(RandVals.randomLong);&lt;br /&gt;
    System.out.println(RandVals.randomFloat);&lt;br /&gt;
    System.out.println(RandVals.randomDouble);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
interface RandVals {&lt;br /&gt;
  Random rand = new Random();&lt;br /&gt;
  int randomInt = rand.nextInt(10);&lt;br /&gt;
  long randomLong = rand.nextLong() * 10;&lt;br /&gt;
  float randomFloat = rand.nextLong() * 10;&lt;br /&gt;
  double randomDouble = rand.nextDouble() * 10;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;3&lt;br /&gt;
-6942612165866507216&lt;br /&gt;
-8.1946244E18&lt;br /&gt;
5.045338828500432&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Interfaces and Abstract Classes ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;OL&amp;gt;&amp;lt;LI&amp;gt;The interface should be regarded as a contract between a service provider and its clients.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;An abstract class is a class that cannot be instantiated&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;An abstract class must be implemented by a subclass.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;In Java, the interface is a type.&amp;lt;/LI&amp;gt;&amp;lt;/OL&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Follow this format to write an interface:&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
accessModifier interface interfaceName {&lt;br /&gt;
}&lt;br /&gt;
public interface Printable {&lt;br /&gt;
         void print (Object o);&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&amp;lt;OL&amp;gt;&amp;lt;LI&amp;gt;The Printable interface has a method, print.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;print is public even though there is no public keyword.&amp;lt;/LI&amp;gt;&amp;lt;/OL&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Interfaces and Multiple Inheritance ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
interface HisInterface {&lt;br /&gt;
}&lt;br /&gt;
interface HerInterface {&lt;br /&gt;
}&lt;br /&gt;
public interface MyInterface extends HisInterface, HerInterface {&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Interfaces and Polymorphism: Using Multiple Interfaces ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
interface ThisInterface {&lt;br /&gt;
  public void thisMethod();&lt;br /&gt;
}&lt;br /&gt;
interface ThatInterface {&lt;br /&gt;
  public void thatMethod();&lt;br /&gt;
}&lt;br /&gt;
class MyClass implements ThisInterface, ThatInterface {&lt;br /&gt;
  // Class definition including methods from both interfaces...&lt;br /&gt;
  public void thisMethod() {&lt;br /&gt;
    System.out.println(&amp;quot;this&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
  public void thatMethod() {&lt;br /&gt;
    System.out.println(&amp;quot;that&amp;quot;);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] a) {&lt;br /&gt;
    MyClass cls = new MyClass();&lt;br /&gt;
    cls.thisMethod();&lt;br /&gt;
    cls.thatMethod();&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;this&lt;br /&gt;
that&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Multiple interfaces ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
interface A {&lt;br /&gt;
  void aMethod();&lt;br /&gt;
}&lt;br /&gt;
interface B {&lt;br /&gt;
  void bMethod();&lt;br /&gt;
}&lt;br /&gt;
interface C {&lt;br /&gt;
  void cMethod();&lt;br /&gt;
}&lt;br /&gt;
class ClassA {&lt;br /&gt;
  public void aMethod() {&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
class D extends ClassA implements A, B, C {&lt;br /&gt;
  public void bMethod() {&lt;br /&gt;
  }&lt;br /&gt;
  public void cMethod() {&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void t(A x) {&lt;br /&gt;
    x.aMethod();&lt;br /&gt;
  }&lt;br /&gt;
  public static void u(B x) {&lt;br /&gt;
    x.bMethod();&lt;br /&gt;
  }&lt;br /&gt;
  public static void v(C x) {&lt;br /&gt;
    x.cMethod();&lt;br /&gt;
  }&lt;br /&gt;
  public static void w(ClassA x) {&lt;br /&gt;
    x.aMethod();&lt;br /&gt;
  }&lt;br /&gt;
  public static void main(String[] args) {&lt;br /&gt;
    D h = new D();&lt;br /&gt;
    t(h);&lt;br /&gt;
    u(h);&lt;br /&gt;
    v(h);&lt;br /&gt;
    w(h);&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  Nesting Classes in an Interface Definition ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;An inner class to an interface will be static and public by default.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
interface Port {&lt;br /&gt;
  // Methods &amp;amp; Constants declared in the interface...&lt;br /&gt;
  class Info {&lt;br /&gt;
    // Definition of the class...&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
public class MainClass {&lt;br /&gt;
  public static void main(String[] a) {&lt;br /&gt;
    Port.Info info = new Port.Info();&lt;br /&gt;
  }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==  To implement an interface: use the implements keyword after the class declaration ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- start source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
    &amp;lt;source lang=&amp;quot;java&amp;quot;&amp;gt;&lt;br /&gt;
public class CanonDriver implements Printable {&lt;br /&gt;
         public void print (Object obj) {&lt;br /&gt;
             // code that does the printing&lt;br /&gt;
         }&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
    &lt;br /&gt;
   &lt;br /&gt;
  &amp;lt;!-- end source code --&amp;gt;&lt;br /&gt;
   &lt;br /&gt;
&lt;br /&gt;
&amp;lt;OL&amp;gt;&amp;lt;LI&amp;gt;An implementation class has to override all methods in the interface.&amp;lt;/LI&amp;gt;&amp;lt;LI&amp;gt;A class can implement multiple interfaces.&amp;lt;/LI&amp;gt;&amp;lt;/OL&amp;gt;&lt;/div&gt;</summary>
			</entry>

	</feed>