Question 1

(a) Explain final and super by giving examples.
class H
{
final void show()
{
System.out.println("Final Method. Cant Override");
}
}
final class E extends H
{
//void show()
//{
// Can Not Override Final Method from H
//}
}
//class J extends E
//{
// Can Not Subclass Of E
//}
public class FinalKeywordSimpleExampleH2E
{
public static void main(String args[])
{
H h = new H();
h.show();
}
}
class employee
{
int employee_id;
String employee_name;
employee(int employee_id, String employee_name)
{
this.employee_id = employee_id;
this.employee_name = employee_name;
}
}
class salary extends employee
{
String designation;
double monthly_salary;
salary(int employee_id, String employee_name,String designation,double monthly_salary)
{
super(employee_id,employee_name);
this.designation = designation;
this.monthly_salary = monthly_salary;
}
void show()
{
System.out.println("Employee Details : ");
System.out.println("Id = "+this.employee_id);
System.out.println("Name = "+this.employee_name);
System.out.println("Designation = "+this.designation);
System.out.println("Salary = "+this.monthly_salary);
}
}
class SuperKeywordSimpleEampleH2E
{
public static void main(String args[])
{
salary s = new salary(1,"Shruti Patel","HR Manager",30000);
s.show();
}
}
(b) Declare a class called employee having employee_id and employee_name as members. Extend class employee to have a subclass called salary having designation and monthly_salary as members. Define following:
- Required constructors
- A method to find and display all details of employees drawing salary more than Rs. 20000/-.
- Method main for creating an array for storing these details given as command line arguments and showing usage of above methods.
class employee
{
int employee_id;
String employee_name;
}
class salary extends employee
{
String designation;
double monthly_salary;
salary()
{}
salary(int employee_id,String employee_name,String designation,double monthly_salary)
{
this.employee_id = employee_id;
this.employee_name = employee_name;
this.designation = designation;
this.monthly_salary = monthly_salary;
}
void findDataAbove20000(String arr[][])
{
for(int i=0;i<arr.length;i++)
{
if( (Double.parseDouble(arr[i][3]) ) > 20000 )
{
System.out.println("Employee Details : ");
System.out.println("Id = "+arr[i][0]);
System.out.println("Name = "+arr[i][1]);
System.out.println("Designation = "+arr[i][2]);
System.out.println("Salary = "+arr[i][3]);
}
}
}
}
public class employeeClassExampleInJavaH2E
{
public static void main(String args[])
{
salary s1[] = new salary[4];
String dataArr[][];
s1[0] = new salary(1,"Jaydip-Panchal","Finance-Manager",18000);
s1[1] = new salary(2,"Pratik-Patel","HR-Manager",29000);
s1[2] = new salary(3,"Arpan-Patel","Project-Manager",25000);
s1[3] = new salary();
try
{
s1[3].employee_id = Integer.parseInt(args[0]);
s1[3].employee_name = args[1];
s1[3].designation = args[2];
s1[3].monthly_salary = Double.parseDouble(args[3]);
//System.out.println(args[0]+args[1]+args[2]+args[3]);
}
catch(NumberFormatException e)
{
System.out.println("Exception : "+ e);
}
dataArr = new String[s1.length][4];
for(int i=0;i<s1.length;i++)
{
dataArr[i][0] = String.valueOf(s1[i].employee_id);
dataArr[i][1] = s1[i].employee_name;
dataArr[i][2] = s1[i].designation;
dataArr[i][3] = String.valueOf(s1[i].monthly_salary);
}
s1[3].findDataAbove20000(dataArr);
}
}

Make Comments..!!


Niraj Sharma
Also whatever you admins say about this section/page. This so called paper solution section is not even compete.
Like · Comment ·
Niraj Sharma
It been q quite a lot of time you people (Admins) updated the paper solution of subjects! What you are sleeping! But abuses apart, I argue and demand to upload paper solutions of the subjects! Damnit you people, even syllabus has changed too, and i havent seen updates in this paper solution section from about 3 n half years.
Like · Comment ·
Admin
Thank you for your feedback. We are agree with you. We will update it as soon as possible,
Like ·
krupa patel
tanxxxx a lot for this solutions
Like · Comment ·
sunanda chhatbar
gr8..!!
Like · Comment ·
Sreejit Pillai
Thanks Guy's..Nice Work !!
Like · Comment ·
Kishan Vasoya likes this
Anu Sha
explain difference between overloading and over ridding
Like · Comment ·
Kiran Kulkarni likes this
Anu Sha
thank you Jaydip
Like · 2 ·
Kiran Kulkarni
Method overloading is concept where same function is used with the different parameter and method overriding is,same function is used in one or more classes by inheriting superclass
Like · 3 ·
Sakhavat Sunasara
explian plz swim
Like ·
Download Android App