EduLearn - Online Education Platform

Welcome to EduLearn!

Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.

Browse Courses

Create an interface Printable with a method print(), implement this interface in classes Document and photo

 

interface Printable

{

void print();

}

 

class Document implements Printable

{

void print()

{

System.out.println(“Document printed”);

}

}

 

class Photo implements Printable

{

void print()

{

System.out.println(“Photo printed”);

}

}

 

class Main

{

public static void main(String args[])

{

Document d=new Document();

Photo p=new Photo();

 

d.print();

p.print();

}}

 

Create an interface Calculator with methods add(),subtract(),multiply(),divide(). Implement those interface in class named calculator

 

interface Calculator

{

int add(int a,int b);

int sub(int a,int b);

int multiply(int a,int b);

int divide(int a,int b);

}

 

class Calculator1 implements Calculator

{

int add(int a,int b){return a+b;}

 

int subtract(int a,int b){return a-b;}

 

int multiply(int a,int b){return a*b;}

 

int divide(int a,int b){return a/b;}

}

class Main

{

public static void main(String args[])

{

Calculator1 c=new calculator1();

 

System.out.println(“Add=” +c.add(10,20));

System.out.println(“Sub=” +c.subtract(50,20));

System.out.println(“Mul=” +c.multiply(10,2));

System.out.println(“Div=” +c.divide(10,5));

}}

Java practice programs for leetcode

Leave a Reply

Your email address will not be published. Required fields are marked *

EduLearn - Online Education Platform

Welcome to EduLearn!

Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.

Browse Courses

Popular Courses

[Course Image]

Introduction to Programming

Learn the fundamentals of programming with Python in this beginner-friendly course.

12 Hours Beginner
[Course Image]

Data Science Essentials

Master the basics of data analysis, visualization, and machine learning.

20 Hours Intermediate
[Course Image]

Web Development Bootcamp

Build modern websites with HTML, CSS, JavaScript and popular frameworks.

30 Hours Beginner
[Course Image]

Digital Marketing Fundamentals

Learn SEO, social media marketing, email campaigns and analytics.

15 Hours Beginner
Educational Website Footer