Program Definition 23 ::
The abstract class Tent has concrete subclasses named TentA, TentB, TentC and TentD. The Waterproof interface defines no constants and declares no methods. Implement it in any two of above mentioned four classes. Define all of these classes, and implement the interfaces as specified. Create one instance of each class. Then display all waterproof tents. Place this code in a package named tents. |
//create tents folder and then write below code
package tents;
abstract class Tent
{
}
class TentA extends Tent implements WaterProof
{}
class TentB extends Tent implements WaterProof
{}
class TentC extends Tent
{}
class TentD extends Tent
{}
interface WaterProof
{}
class Prog23
{
public static void main( String args[] )
{
Tent t[] = new Tent[ 4 ];
t[ 0 ] = new TentA();
t[ 1 ] = new TentB();
t[ 2 ] = new TentC();
t[ 3 ] = new TentD();
for ( Tent ti : t )
{
if ( ti instanceof WaterProof )
{
Class cls = ti.getClass();
System.out.println(cls.getName());
}
}
}
}
/*
D:\JAVA>javac tents/*.java
D:\JAVA>java tents.Prog23
tents.TentA
tents.TentB
*/
0 comments :