0% found this document useful (0 votes)
3 views4 pages

New Microsoft Word Document

The document contains Java code demonstrating the use of interfaces and classes. It includes examples of implementing interfaces for printing and showing messages, calculating the area of a rectangle, and managing student details through input and display methods. The main methods in each class execute these functionalities, showcasing object-oriented programming principles.

Uploaded by

Rohit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

New Microsoft Word Document

The document contains Java code demonstrating the use of interfaces and classes. It includes examples of implementing interfaces for printing and showing messages, calculating the area of a rectangle, and managing student details through input and display methods. The main methods in each class execute these functionalities, showcasing object-oriented programming principles.

Uploaded by

Rohit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

interface Printable{

void print();

interface Showable{

void show();

class InterfaceDemo implements Printable,Showable

public void print()

{System.out.println("Hello");}

public void show()

{System.out.println("Welcome");}

public static void main(String args[])

InterfaceDemo obj = new InterfaceDemo ();

obj.print();

obj.show();

}
interface Polygon {

void getArea(int length, int breadth);

// implement the Polygon interface

class Rectangle implements Polygon {

// implementation of abstract method

public void getArea(int length, int breadth) {

System.out.println("The area of the rectangle is " + (length * breadth));

class Main {

public static void main(String[] args) {

Rectangle r1 = new Rectangle();

r1.getArea(5, 6);

}
import java.util.Scanner;

class StudentDetails {

int roll_no;

String name, cl;

//creating a function to take student details

void input() {

Scanner sc = new Scanner(System.in);

System.out.print("Enter Roll Number: ");

roll_no = sc.nextInt(); //=> 22\n == buffer

sc.nextLine(); // => \n

System.out.print("Enter Name: ");

name = sc.nextLine();

System.out.print("Enter class: ");

cl = sc.nextLine();

class Student extends StudentDetails {

//method to display student details

void display() {
System.out.println("/******* Student details printed ********/");

System.out.println("Roll Number is: "+roll_no);

System.out.println("Your name is: "+name);

System.out.println("Your class is: "+cl);

public static void main(String args[]) {

Student obj = new Student();

obj.input();

obj.display();

You might also like