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

Java OOP Concepts and Exception Handling

The document contains Java programming exercises focused on Object-Oriented Programming (OOP) concepts, including the implementation of interfaces, exception handling, and control flow statements like break and continue. It provides code examples for each exercise along with expected outputs. The exercises are part of a laboratory course in the Department of Computer Science and Design at SUK.

Uploaded by

a70497944
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 views5 pages

Java OOP Concepts and Exception Handling

The document contains Java programming exercises focused on Object-Oriented Programming (OOP) concepts, including the implementation of interfaces, exception handling, and control flow statements like break and continue. It provides code examples for each exercise along with expected outputs. The exercises are part of a laboratory course in the Department of Computer Science and Design at SUK.

Uploaded by

a70497944
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

OOPS With JAVA Laboratory (22CSL38)

6. Write a Java program that implements interface using extends keyword

interface A

void funcA( );

interface B extends A

void funcB( );

class C implements B

public void funcA( )

[Link]("This is funcA");

public void funcB( )

[Link]("This is funcB");

public class Demo

public static void main(String args[ ])

C obj = new C();

[Link]();

Dept. of Computer Science and Design 1


Faculty of Engineering & Technology, SUK
OOPS With JAVA Laboratory (22CSL38)

[Link]();

Output

This is funcA

This is funcB

Dept. of Computer Science and Design 2


Faculty of Engineering & Technology, SUK
OOPS With JAVA Laboratory (22CSL38)

7.a. write a java program that illustrate exception handling mechanism .

[Link].*;

class Error2

public static void main(String args[ ])

int a=10;

int b=5;

int c=5;

intx,y;

try

x=a/(b-c);

catch (ArithmeticException e)

[Link]("division by zero");

y=a/(b+c);

[Link]("y=" +y);

Output:

C:\javaprg>javac [Link]

[Link]:x is already defined in main<[Link] [ ] >

Dept. of Computer Science and Design 3


Faculty of Engineering & Technology, SUK
OOPS With JAVA Laboratory (22CSL38)

Intx = a / < b - c >;

[Link]:x is already defined in main<[Link] [ ] >

Int y = a / < b + c >;

2 errors

C:\javaprg>javac [Link]

C:\javaprg>java Error2

Division by zero

y=1

7.b. write a java program to implement break and continue statements.

class BreakandContinue

public static void main(String args[ ])

//Illustrating break statement (execution stops when value of i becomes to 4.)

[Link]("Break Statement\n....................");

for(inti=1;i<=5;i++)

if(i==4) break;

[Link](i);

// Illustrating continue statement (execution skipped when value of i becomes to 1.)

[Link]("Continue Statement\n....................");

for(inti=1;i<=5;i++)

Dept. of Computer Science and Design 4


Faculty of Engineering & Technology, SUK
OOPS With JAVA Laboratory (22CSL38)

if(i==1) continue;

[Link](i);

Output:

Break statement

…………………………………

Continue statement

……………………….

Dept. of Computer Science and Design 5


Faculty of Engineering & Technology, SUK

You might also like