Question

Code using Java What is an interface? Complete the following code: interface IExample{ public void print();...

Code using Java

What is an interface? Complete the following code:
interface IExample{
public void print();
}
class Example1 implements IExample{
. . .
}
// Driver class
public class Questions
{
public static void main(String[] args)
{
. . .
}
}
To have this message when you execute it:
Implementation of an interface
0 0
Add a comment Improve this question Transcribed image text
Answer #1

/**
*Interface is an collection methods which are abstract by default
*/
interface IExample {
   public void print();
}

class Example1 implements IExample {

   @Override
   public void print() {
       System.out.println("Implementation of an interface");
   }

}

// Driver class
public class Questions {
   public static void main(String[] args) {
       IExample i = new Example1();
       i.print();
   }
}

Add a comment
Know the answer?
Add Answer to:
Code using Java What is an interface? Complete the following code: interface IExample{ public void print();...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Consider the following Java 8 code, and select true statements: public interface Functionlnterfac...

    Consider the following Java 8 code, and select true statements: public interface Functionlnterface1 void abstFun1 (int x) public interface Functioninterface2( void abstFun2(int x); public class Main implements Functioninterface2( @Override public void abstFun2(int x) System.out.printin(3'x); public static void main(Stringl args) ( Functioninterface1 fobj (int x)->System.out.printin(2"x) fobj.abstFun1(5); Main me - new Main; me.abstFun2(5); Functioninterface2 fobj2-(int x)->System.out.printin(4%; fobj2.abstFun2(5) 2 in main will not run because abstFun2 was previoudly implemented. O The fobj instance of Functionlnterface1 is created using the lambda at runtime without...

  • Suppose we have the following Java Interface: public interface Measurable {    double getMeasure(); // An...

    Suppose we have the following Java Interface: public interface Measurable {    double getMeasure(); // An abstract method    static double average(Measurable[] objects) { // A static method    double sum = 0;    for (Measurable obj : objects) {    sum = sum + obj.getMeasure();    }    if (objects.length > 0) { return sum / objects.length; }    else { return 0; }    } } Write a class, called Person, that has two instance variables, name (as...

  • Show the output of running the class Test in the following code lines: interface A {...

    Show the output of running the class Test in the following code lines: interface A { void print (); } class C ( class B extends C implements A { public void print() { } } class Test { public static void main(String[] args) { B b = new B(); if (b instanceof A) System.out.println("b is an instance of A"); w class Test { public static void main(String[] args) { B b = new B(); if (b instanceof A) System.out.println("b...

  • What will the code shown below print to the console? public class Cascade public static void...

    What will the code shown below print to the console? public class Cascade public static void print(int arg){ for(int i=0; i<arg; i++){ System.out.print(""); } System.out.println(""); if(arg > 1){ print(arg-1); } } public static void main(String[] args) { print(4); } } E B IV AA- IES XX, SE V GT 12pt Paragraph -

  • What will be the output of the following Java code? class Output { public static void...

    What will be the output of the following Java code? class Output { public static void main(String args[]) { boolean a = true; boolean b = false; boolean c = a ^ b; System.out.println(!c); } } a) 0 b) 1 c) false d) true

  • What is wrong with the following Java Code. public class TestEdible { abstract class Animal {...

    What is wrong with the following Java Code. public class TestEdible { abstract class Animal { /** Return animal sound */ public abstract String sound(); } class Chicken extends Animal implements Edible { @Override public String howToEat() { return "Chicken: Fry it"; } @Override public String sound() { return "Chicken: cock-a-doodle-doo"; } } class Tiger extends Animal { @Override public String sound() { return "Tiger: RROOAARR"; } } abstract class Fruit implements Edible { // Data fields, constructors, and methods...

  • Question 28 public class Main public static void main(String args[]) { Iparentp=new Child (1.2); p.printo: interface...

    Question 28 public class Main public static void main(String args[]) { Iparentp=new Child (1.2); p.printo: interface Iparent public int x = 1; public void printo: class Child implements Iparent private int y public Child(int a, int b) y b: public void printot System.out.print("Child"-yl: Child 2 public int x = 1; public void print(); class Child implements Iparent! private int y public Child(int a, in lb) y=b; public vold print! System.out.pnt("Child"+y): Child 2 1 None of the above • Previous

  • Java -Create an interface and implement it In the murach.db package, create an interface named IProductDB....

    Java -Create an interface and implement it In the murach.db package, create an interface named IProductDB. This interface should specify this abstract method: public abstract Product get(String productCode); Modify the ProductDB class so it implements the IProductDB interface. Write the code for the new ‘get’ method. Then remove the getProductByCode method. In the Main class, modify the code so it works with the new ProductDB class. This code should create an instance of the IProductDB interface like this: IProductDB db...

  • What is the Java output? Part One: class Driver { public static void main(String[] args) {...

    What is the Java output? Part One: class Driver { public static void main(String[] args) { int a = 5; int b = 3; if (a < b || a * 2 < b) System.out.print(a - b); System.out.print(b + a); } } Part Two: class Driver { public static void main(String[] args) { int a = 5; int b = 8; if (a < b) if (a * 2 < b) System.out.print("foo"); else System.out.print("bar"); else System.out.print("buz"); } }

  • 1. Analyze the following code: public class Test implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); t.start(); } public void run() { System....

    1. Analyze the following code: public class Test implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); t.start(); } public void run() { System.out.println("test"); } } 1. The code compiles but will not print anything since t does not invoke the run method. 2. The code will not compile since you cannot invoke "this" in a static method. 3. The program compiles, runs, and prints tests on the console. 2. What will the following example...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT