Write a program in java to create interface named test. in this interface the member function is square. implement this interface in arithmetic class. create one new class called totestint. in this class use the object of arithmetic class.
Answers
Answer:
abcdefghjiklmnopqrst
Answer: Java program is written below.
Explanation:
To Find : Write a program in java to create interface named test. in this interface the member function is square. implement this interface in arithmetic class. create one new class called totestint. in this class use the object of arithmetic class.
Concept :
An Interface in Java programming language is described as an abstract type used to specify the behavior of a class. A Java interface contains static constants and abstract methods and it is used to achieve abstraction.
// Interface
public interface Test
{
public int square(int a);
}
// Implements
class arithmetic implements Test
{
int s = 0;
public int square(int b)
{
System.out.println(“Inside arithmetic class – implemented method square”);
System.out.println(“Square of “ + “ is “+s);
return s;
}
void armeth()
{
System.out.println(“Inside method of class Arithmetic”);
}
}
// use the object
class ToTestInt
{
public static void main(String a[])
{
System.out.println(“calling from ToTestInt class maiin method”);
Test t = new arithmetic();
System.out.println(“==============================”);
System.out.println(“Object of test interface is created through Arithmetic class ");
System.out.println(“Hence Arithmetic class method square is called”);
System.out.println(“This object cannot call armeth method of
Arithmetic class”);
System.out.println(“=================================”);
t.square(10);
System.out.println(“=================================”);
}
}
__________________________________________________
Related links :
What is interface in java ?
https://brainly.in/question/13964915
What is Functional Interface in Java 8?
https://brainly.in/question/9118507
#SPJ3