1.java Classes To Explain Inheritance: Package Class Float Class Extends Int Public Static Void New
1.java Classes To Explain Inheritance: Package Class Float Class Extends Int Public Static Void New
package End_Sem_Exam;
class Employee{
float salary=40000;
}
class programmer extends Employee{
int bonus=10000;
public static void main(String args[]){
programmer p=new programmer();
System.out.println("programmer salary
is:"+p.salary);
System.out.println("Bonus of programmer
is:"+p.bonus);
}
}
//this explains inheritance
//programmer inherits employee
2.Finding Largest Number in an Array
package End_Sem_Exam;
package end_Sem_Exam2;
class Factorial{
static int factorial(int n){
if (n == 0)
return 1;
else
return(n * factorial(n-1));
}
public static void main(String args[]){
int i,factorial=1;
int number=5;//It is the number of which
we want to find factorial
factorial = factorial(number);
System.out.println("Factorial of
"+number+" is: "+factorial);
}
}
4.Usage of string and StringBuffer
package end_Sem_Exam2;
class Stbuffer{
public static void main(String args[]){
System.out.println("Hashcode of
String:");
String str="java";
System.out.println(str.hashCode());
str=str+"satya";
System.out.println(str.hashCode());
System.out.println("Hashcode of
StringBuffer:");
StringBuffer sb=new
StringBuffer("java");
System.out.println(sb.hashCode());
sb.append("satya");
System.out.println(sb.hashCode());
}
}
5.Adding and Removing From a Array List
package end_Sem_Exam2;
import java.util.ArrayList;
class book
{
public static void main(String[] args)
{
book.remove("digital image
processing");//Removing one book(digital image
processing) from the //arraylist
System.out.println("The elements of
the arraylist are"+book);
}
}