Master the exact 4 questions from Part 1 of your Wednesday test paper: Jagged Arrays, Interface Contracts, Explicit Constructors with Setters, and Single-Table Superclass-Subclass Inheritance.
Write a Java program segment to initialize and display a 2D array called data with three rows that have the following data elements: row 1 {2, 3, 7}, row 2 {7}, and row 3 {9, 6}.
data[i].length inside the inner loop (rather than hardcoding a fixed size like 3). Hardcoding data[0].length for all rows causes an ArrayIndexOutOfBoundsException when reading row 2!
Write a program to display the name, programme, year and registration number of a University student using interface mechanism.
public abstract. If you forget to write public in UniversityStudent, Java assumes package-private visibility, which reduces method visibility and causes a COMPILE ERROR!
Create an Employee class with four instance variables name, age, designation and salary. The class has one explicitly defined constructor, which takes a parameter. The instance variable name is assigned in the constructor. Add methods to assign all the other instance variables of the class. Add a method to print Employee details. Create two objects and test the program.
public Employee(String name), Java automatically deleted the default no-arg constructor. If you attempt Employee emp = new Employee();, compiler throws an error! You MUST pass the `name` parameter upon instantiation.
Write a Java program that demonstrates inheritance.
Requirements:
(i) Create a superclass named Employee with attributes: employeeID, name, salary.
(ii) Include a constructor and a method displayEmployee().
(iii) Create a subclass named Manager that extends Employee.
(iv) Add an additional attribute department.
(v) Include a method displayManager() that displays all employee details including the department.
(vi) Create an object of Manager and display its information.