Assignment 01 JavaProgramming
Assignment 01 JavaProgramming
Instructions:
1- Create a folder name Assignment_01 in the same workspace where
you have created Unit_01 and Unit_02. Kindly follow the image.
2- Create Q1, Q2, Q3 and so on for all coding related questions in this
assignment
Q2- WAP to count the total number of calls for a member function from
more than one objects. [Let’s say, from 3 such Objects]
Q3- Given an interface in1 which includes a method display which takes
an integer as input .
interface In1
{
void display(int p);
}
Task is to write a class testClass which implements interface In1 and has
a method named display which takes an integer as an input p and the
display method should be able to tell if the number is prime or not?
- The main method should not be in testClass, create a separate class for
that.
Create an object of top child class and make sure the constructor
execution will take place according to respective multi-level inheritance
hierarchy.
Restrictions:
1- Minimum 8 objects [can be created manually with parameterized
constructors with Scanner input]
2- Departments are, A, B, C, D: minimum 4 departments [String Type]
3- If the Salary exceeds more than 30,000, then the default salary
would be 25000 of any of the employee
4- Use array of objects, instead of using multiple 8 objects separately
Use:
Employee arr[] = new Employee[8];
And
arr[i].department.equals("A");
Q6. As given there are two sample methods: First one returns the sum of
two numbers a and b and second one returns the subtraction of a and b. if
a-b is negative then return value would be 0. Use ternary operator to call
these two methods. If a>b then ternary should call sum(a,b) but if a<b
then ternary operator should call sub(a,b). Eventually print the result of
the ternary operation on variable a and b.
Note: Ternary operator can call a method even for true and false values
Q7. WAP to count the total number of calls for a member function:
display(), from more than one objects and how many times the object is
created of a class name Employee.
Note: Call display() function from more than 3 objects
Q8. WAP in java, to delete index=3, element from the given array
mentioned below.
Q10. WAP in Java Program To Survey Four Different Car Models For Four
Different Cities:
Your job is to find out the total number of cars sold of each model in all
the cities. Use Array of objects or multiple objects of class name City.
Q11. As given there are two sample methods: First one returns the sum of
two numbers a and b and second one returns the subtraction of a and b. if
a-b is negative then return value would be 0. Use ternary operator to call
these two methods. If a>b then ternary should call sum(a,b) but if a<b
then ternary operator should call sub(a,b). Eventually print the result of
the ternary operation on variable a and b.
Note: Ternary operator can call a method even for true and false values
Q13. How Compiler And Jvm Can Differentiate Constructor And Method
Definitions Of Both Have Same Class Name?
Abstract Class:
1. Pure or 100% abstract class
2. Normal Abstract Class [0-100% abstract methods]
Q18. How local static variable is different from global static variable?
Q20. What happens if we add final keyword with Class, Method and a
variable in java. Explain it through suitable code if required.