30. An example of multiple inheritance –

class Student {                 int rollNumber;                 void getNumber(int n)                 {                                 rollNumber=n;                 }                 void putNumber()                 {                                 System.out.println("Roll No : "+rollNumber);                 } } class Test extends Student {                 float part1,part2;                 void getMarks(float m1,float m2)                 {                                 part1=m1;                                 part2=m2;                 }                 void putMarks()                 {... Continue Reading →

Advertisements

29. An example of single interface –

interface Area   //Interface Defined {                 final static float pi=3.14f;                 float compute(float x,float y); } class Rectangle implements Area              //Interface Implemented {                 public float compute(float x,float y)                 {                                 return (x*y);                 } } class Circle implements Area       //Auther Implementation {                 public float compute(float x,float y)                 {                                 return (pi*x*x);... Continue Reading →

28. An example of string class with an array of string –

class StringTest {                 static String name[]={"Vivek","Lalit","Prince","Aruni","Sachin","Phrabhat","Vikrant"};                 public static void main(String args[])                 {                                 String temp=null;                                 int size=name.length;                                 for(int i=0;i<size-1;i++)                                 {                                                 for(int j=i+1;j<size;j++)                                                 {                                                                 if(name[j].compareTo(name[i])<0)                                                                 {                                                                                 temp=name[i];                                                                                 name[i]=name[j];                                                                                 name[j]=temp;                                                                 }                                                 }                                 }                 for(int i=0;i<size;i++)                                 System.out.println(name[i]);                 } }

27. Write a program in java to input nine integers in three rows and three columns. Calculate and print sum of both diagonal value?

class SumDiagonal {                 public static void main(String args[])                 {                                 int n[][]={{1,2,3},{4,5,6},{7,8,9}};                                 int i,j=3,s=0;                                 for(i=0;i<3;i+)                                 {                                                 j--;                                                 s+=n[i][i]+n[i][j];                                 }                                 System.out.println("Sum Diagonal = "+s);                 } }

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: