0% found this document useful (0 votes)
23 views

Wap To Implement Abstract Class

This document contains code snippets for various Java programs that demonstrate object-oriented programming concepts like abstract classes, inheritance, exception handling, and use of static keyword. The programs include implementations for Armstrong number check, Fibonacci series, outer class, palindrome check, and exception handling using try-catch blocks and multi-catch.

Uploaded by

Avinash Singh
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Wap To Implement Abstract Class

This document contains code snippets for various Java programs that demonstrate object-oriented programming concepts like abstract classes, inheritance, exception handling, and use of static keyword. The programs include implementations for Armstrong number check, Fibonacci series, outer class, palindrome check, and exception handling using try-catch blocks and multi-catch.

Uploaded by

Avinash Singh
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

WAP TO IMPLEMENT ABSTRACT CLASS:

abstract class A

abstract void callme();

void callmetoo()

System.out.println("this is a concrete method");

class B extends A

void callme()

System.out.println("B 's implementation of callme");

class AbstractDemo

public static void main(String arg[])

B b=new B();

b.callme();

b.callmetoo();

}
WAP TO CHECK WHETHER A NUMBER IS
ARMSTRONG OR NOT.
class Armstrong

public static void main(String arg[])

int num,n,sum,r;

num=Integer.parseInt(arg[0]);

n=num;

sum=0;

while(n!=0)

r=n%10;

sum=sum+r*r*r;

n=n/10;

if(sum==num)

System.out.println("The number is armstrong" + "" +sum);

else

System.out.println("The number is not armstrong" + "" +sum);

}
WAP TO PRINT FIBONACCI SERIES:
class Fibonacci

public static void main(String arg[])

int a,b,next,limit;

limit=Integer.parseInt(arg[4]);

a=0;

b=1;

next=a+b;

while(next<=limit)

a=b;

b=next;

next=a+b;

System.out.println(next);

}
IMPLEMENT A PROGRAM USING THE CONCEPT OF
OUTER CLASS
class Outer

int o_x=100;

void test()

Inner i=new Inner();

i.display();

class Inner

void display()

System.out.println("display o_x="+ o_x);

class Demo

public static void main(String arg[])

Outer o=new Outer();

o.test();

}
WAP TO CHECK WHETHER A NUMBER IS
PALINDROME OR NOT:
class Palindrome

public static void main(String arg[])

int r,num,n,rev=0;

num=Integer.parseInt(arg[0]);

n=num;

while(n!=0)

r=n%10;

rev=rev*10+r;

n=n/10;

if(rev==num)

System.out.println("No. is Palindrome" + "" + num);

}
IMPLEMENT A PROGRAM USING KEYWORD
STATIC:
class A

static int a=3;

static int b;

static void meth(int x)

System.out.println("x=" + x);

System.out.println("a=" +a);

System.out.println("b="+ b);

static

System.out.println("static block initialized");

b=a*4;

public static void main(String arg[])

meth(55);

}
WAP TO IMPLEMENT INHEHITANCE
class A

int i;

class B extends A

int i;

B(int a,int b)

super.i=a;

i=b;

void show()

System.out.println("i in superclass" + super.i);

System.out.println("i in subclass" + i);

class Use

public static void main(String arg[])

B obj = new B(1,2);

Objb;

}
WAP FOR EXCEPTION HANDLING:
class Throwdemo

static void demoproc()

try

throw new NullPointerException (“demo”);

Catch(NullPointerException e)

System.out.println(“caught inside demoproc”);

Throw e;

Public static void main(String ar[])

Try

Demoproc();

Catch(NullPointerException e)

System.out.println(“recaught”+e);

}
OUTPUT:
Caught inside demoproc

Recaughtjava.lang.NullPointerException:demo
WAP FOR EXCEPTION HANDLING:
Class Multicatch

Public static void main(String ar[])

Try

int a=ar.length;

System.out.println(“a=”+a);

Int b=42/a;

Int c[]={1};

C[42]=99;

Catch(ArithmeticException ae)

System.out.println(“divide by zero”+ae);

Catch(ArrayIndexOutOfBoundsException e)

System.out.println(“array index out of bound”+e);

System.out.println(“after try catch blocks”);

}
OUTPUT:
a=0

divide by zerojava.lang.ArithmeticException:/by zero

after try catch blocks


WAP FOR EXCEPTION HANDLING:
Class E

Public static void main(String ar[])

Int d,a;

Try

D=0;

A=42/d;

System.out.println(“exception”);

Catch(ArithmeticException e)

System.out.println(“divide by zero error”);

OUTPUT:
Divide by zero error
Dronacharya College of
Engineering

OBJECT ORIENTED
TECHNIQUES LAB FILE

SUBMITTED TO: SUBMITTED BY:


Ms. Sarika Gaurav rana
CSE-v (sem)
0823010017
INDEX

Sno Program date sign


S.no Program Date Sign.
.

You might also like