Java example code, how to use extends and implements in class package myjavaexample; public class MyJavaExample { private interface DoSomething { public void sound(); } private class Animal { public String voice= "Animal" ; public Animal() { } public Animal(String voice) { this .voice=voice; } } private class Pet extends Animal implements DoSomething { public Pet() { } public Pet(String voice) { super(voice); } public void sound() { System.out.println( this .voice); } } public void experiment() { Pet dog= new Pet(); dog.sound(); Pet cat= new Pet( "Miauww" ); cat.sound(); Pet bird= new Pet( "Cici" ); bird.sound(); } ...
This is Java code example to calculate factorial problem package myjavaexample; public class MyJavaExample { public static void main(String[] args) { int n=8,result=1; for ( int i=n;i>0;i--){ result*=i; } System.out.println(n+ "! = " +result); } }
Comments
Post a Comment