Robot(Inheritance of interfaces): an easy program
Create an abstract class Robot that has the concretre subclasses ,RobotA, RobotB, RobotC. Class RobotA1 extends RobotA, RobotB1 extends RobotB and RobotC1 extends RobotC. There is interface Motion that declares 3 methods forward(), reverse() and stop(), implemented by RobotB and RobotC. Sound interf
JAVA videos
An interface in Java has a static constants and abstract methods. It is a mechanism to achieve abstraction. There can be only abstract methods in it, not method body. It is used to achieve abstraction and multiple inheritance in Java.
Create an abstract class Robot that has the concretre subclasses ,RobotA, RobotB, RobotC. Class RobotA1 extends RobotA, RobotB1 extends RobotB and RobotC1 extends RobotC. There is interface Motion that declares 3 methods forward(), reverse() and stop(), implemented by RobotB and RobotC. Sound interface declare method beep() implemented by RobotA1, RobotB1 and RobotC1. Create an instance method of each class and invoke beep() and stop() method by all objects.
abstract class Robot
{}
interface Motion
{
void forward();
void reverse();
void stop();
}
interface Sound
{
void Beep();
}
class RobotA extends Robot
{}
class RobotB extends Robot
{}
class RobotC extends Robot
{}
class RobotA1 extends RobotA implements Sound
{
public void stop()
{
System.out.println("Stop in RobotA1");
}
public void Beep()
{
System.out.println("Beep in RobotA1");
}
}
class RobotB1 extends RobotB implements Sound, Motion
{
public void forward()
{}
public void reverse()
{}
public void stop()
{
System.out.println("Stop in RobotB1");
}
public void Beep()
{
System.out.println("Beep in RobotB1");
}
}
class RobotC1 extends RobotC implements Sound, Motion
{
public void forward()
{}
public void reverse()
{}
public void stop()
{
System.out.println("Stop in RobotC1");
}
public void Beep()
{
System.out.println("Beep in RobotC1");
}
}
public class Practical18
{
public static void main(String[] args)
{
RobotA1 ra = new RobotA1();
RobotB1 rb = new RobotB1();
RobotC1 rc = new RobotC1();
ra.Beep();
ra.stop();
rb.Beep();
rb.stop();
rc.Beep();
rc.stop();
}
}
Interface programs
Related Posts
Continue learning with these related articles

ISC Practical 2027: Image Editor – Brighten an Image and Find Bright Spots (2-D Array) – Java Program
Fully solved ISC Computer Science Practical 2027 2-D array question: brighten a grayscale image (capping values at 255) and find the bright spots, pixels larger than all four neighbours. Includes a missing bright spot in CISCE’s sample output.

ISC Practical 2027: College Enrolment Code Validator and Stream Report – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 question: validate college enrolment codes made of a stream, year and serial number, give the exact reason for each rejection, auto-correct lowercase streams and prepare a stream-wise report.

ISC Practical 2027: Digital Lock Security Code Analyzer – Algorithm and Java Program
Fully solved ISC Computer Science Practical 2027 number-logic question: for a 5 to 10 digit security code, find the first and last digits, odd and even position sums, product of non-zero digits, digit frequency and classify the code as STRONG, MODERATE or WEAK.