Font size
WorksheetsJAVA PROGRAMMING EXAM BSAIT 1-2
Total questions: 54
Worksheet time: 2hrs 41mins
What is inheritance in Java?
A mechanism where one object modifies properties and behaviors of a parent object
A mechanism where one object creates properties and behaviors of a parent object
A mechanism where one object loses properties and behaviors of a parent object
A mechanism where one object acquires properties and behaviors of a parent object
What does the 'extends' keyword indicate in Java?
Creating a new class that is a copy of an existing class
Creating a new class that replaces an existing class
Creating a new class that is unrelated to any existing class
Creating a new class that derives from an existing class
What is the superclass in Java inheritance?
The class being inherited from
A class that is a copy of another class
The class that inherits from another class
A class that is unrelated to any other class
What types of inheritance are supported in Java?
Single, hybrid, and hierarchical
Single, multiple, and hybrid
Single, multilevel, and hierarchical
Single, multilevel, and hybrid
What is the relationship between Programmer and Employee classes?
Programmer IS - A Employee
Programmer IS - NOT A Employee
Programmer IS - EQUAL TO Employee
Programmer IS - LIKE A Employee
What is an example of single inheritance in Java?
Dog class inherits the Cat class
Cat class inherits the Dog class
Dog class inherits the Animal class
Animal class inherits the Dog class
What is an example of multilevel inheritance in Java?
BabyDog class inherits the Dog class which inherits the Animal class
Dog class inherits the Animal class
Cat class inherits the Animal class
Animal class inherits the Dog class
What is an example of hierarchical inheritance in Java?
Dog and Cat classes inherit the Animal class
Dog class inherits the Animal class
Cat class inherits the Animal class
Animal class inherits the Dog and Cat classes
How is multiple and hybrid inheritance supported in Java?
Through inheritance only
Through interface only
Through classes only
Through abstract classes only
What does the 'extends' keyword do in Java inheritance?
Changes the functionality of a class
Does not affect the functionality of a class
Decreases the functionality of a class
Increases the functionality of a class
Which term best describes polymorphism in Java?
Singular form
Consistent code
Static method
Single method rendering
Dynamic operation
What is one of the primary benefits of polymorphism in Java?
Increased code inconsistency
Enhanced program complexity
Code reusability
Static method execution
Performance optimization
What challenge does polymorphism in Java introduce to code development?
Reduced flexibility
Simplified maintenance
Increased performance
Enhanced readability
Potential code complexity
What is a potential drawback of polymorphism in Java?
Decreased program flexibility
Reduced code reuse
Simplified debugging process
Increased performance efficiency
Dynamic method binding overhead
Which statement best summarizes the role of polymorphism in Java programming?
It hinders code maintenance and extension.
It simplifies object interactions by enforcing strict type hierarchies.
It allows for the creation of consistent code through shared interfaces.
It eliminates the need for method overloading in object-oriented design.
It prioritizes performance optimization over code flexibility.
Which term best describes the concept of inheritance in Java?
Code encapsulation
Property acquisition
Method overloading
Data abstraction
Object instantiation
What is the relationship between the subclass and superclass in Java inheritance?
Subclass IS-A superclass
Subclass HAS-A superclass
Subclass IMPLEMENTS superclass
Subclass ENCAPSULATES superclass
superclass EXTENDS subclass
Which type of inheritance involves a chain of inheritance?
Single inheritance
Multilevel inheritance
Hierarchical inheritance
Hybrid inheritance
Multiple inheritance
In Java, how is multiple inheritance achieved?
Through the extends keyword
Through the implements keyword
Through the super keyword
Through the extends and implements keywords together
Multiple inheritance is not directly supported in Java
What does the phrase "Programmer IS-A Employee" signify in Java inheritance?
Programmer class has an instance of Employee class
Employee class has an instance of Programmer class
Programmer class inherits from Employee class
Employee class inherits from Programmer class
Programmer class and Employee class are unrelated
class Main {
static void display() {
System.out.println("Static Method Called");
}
public void show() {
System.out.println("Instance Method Called");
}
}
public class Test {
public static void main(String[] args) {
Main.display();
}
}
Given the following Java class definition, what will be the output when calling Main.display()?
Instance Method Called
Static Method Called
Compile-time error
Runtime error
Which of the following statements is true about static methods in Java?
Static methods can only access static data members and static methods of the same class.
Static methods can access both static and non-static data members and methods of the same class.
Static methods can only be called after creating an instance of the class.
Static methods cannot be overloaded.
Which statement is correct regarding the following code snippet?
class Test1 {
public void instanceMethod() {
System.out.println("Instance Method");
}
static void staticMethod() {
instanceMethod();
}
}
public class Test {
public static void main(String[] args) {
Test1 p = new Test1();
p.staticMethod();
}
}
"Instance Method" is printed
The program is correct but no output
The program is Error
Given the following code, How many object im going to create if i want to see both literal strings?
class MethodsExample {
public static void staticMethod() {
System.out.println("Static method called");
}
public void publicMethod() {
System.out.println("Public method called");
}
}
public class MethodExample {
public static void main(String[] args) {
How many object im going to write here
}
}
(a)
What is the output of the program below.
class MethodsExample {
static void staticMethod() {
System.out.println("Static method called");
}
public void publicMethod() {
System.out.println("Public method called");
}
}
public class MethodExample {
public static void main(String[] args) {
MethodsExample example = new MethodsExample();
example.publicMethod();
example.staticMethod();
}
}
Public method called
Static method called
No output but the program is correct
The syntax of object is incorrect
The syntax of syntax of calling a method is incorrect
How many objects im going to create to show all the literal strings provided in the code below.
class MethodsExample {
static void staticMethod() {
System.out.println("Static method called");
}
public void publicMethod() {
System.out.println("Public method called");
}
}
class MethodsExamples {
static void statics() {
System.out.println("Static method called");
}
public void publics() {
System.out.println("Public method called");
}
}
public class MethodExample {
public void publicMethods() {
System.out.println("Publics method called");
}
public static void main(String[] args) {
}
}
(a)
How many object im going to create to show all the literal strings below.
class MethodsExample {
static void staticMethod() {
System.out.println("Static method called");
}
public void publicMethod() {
System.out.println("Public method called");
}
}
class MethodsExamples {
static void statics() {
System.out.println("Static method called");
}
public void publics() {
System.out.println("Public method called");
}
}
public class MethodExample {
static void publicMethods() {
System.out.println("Publics method called");
}
(a)
import java.util.Scanner;
class Employee {
protected Scanner scanner = new Scanner(System.in);
public static double salary = 0;
}
class FullTimeEmployee extends Employee {
void computeSalar() {
System.out.print("Enter the monthly salary for full-time employee: ");
double monthlySalary = scanner.nextDouble();
salary = monthlySalary * 12;
System.out.println("Annual salary of full-time employee: " + salary);
}
}
class PartTimeEmployee extends FullTimeEmployee {
void computeSalary() {
System.out.print("Enter the hourly rate for part-time employee: ");
double hourlyRate = scanner.nextDouble();
System.out.print("Enter the number of hours worked per week: ");
double hoursPerWeek = scanner.nextDouble();
salary = hourlyRate * hoursPerWeek * 4 * 12;
System.out.println("Annual salary of part-time employee: " + ++salary);
}
}
public class Main {
public static void main(String[] args) {
PartTimeEmployee partTimeEmployee = new PartTimeEmployee();
System.out.println("Calculating annual salary of a full-time employee:");
partTimeEmployee.computeSalar();
System.out.println("\nCalculating annual salary of a part-time employee:");
partTimeEmployee.computeSalary();
}
}
Analyzation : Given the program below. What is annual salary of a part time employee is he worked for 12 hours a week and his rate is 12 pesos per hour.
(a)
import java.util.Scanner;
class Employee {
protected Scanner scanner = new Scanner(System.in);
public static double salary;
}
class FullTimeEmployee extends Employee {
void computeSalar() {
System.out.print("Enter the monthly salary for full-time employee: ");
double monthlySalary = scanner.nextDouble();
salary = monthlySalary * 45;
System.out.println("Annual salary of full-time employee: " + ++salary);
}
}
class PartTimeEmployee extends FullTimeEmployee {
void computeSalary() {
System.out.print("Enter the hourly rate for part-time employee: ");
double hourlyRate = scanner.nextDouble();
System.out.print("Enter the number of hours worked per week: ");
double hoursPerWeek = scanner.nextDouble();
salary = hourlyRate * hoursPerWeek * 4 * 12;
System.out.println("Annual salary of part-time employee: " + ++salary);
}
}
public class Main {
public static void main(String[] args) {
PartTimeEmployee partTimeEmployee = new PartTimeEmployee();
System.out.println("Calculating annual salary of a full-time employee:");
partTimeEmployee.computeSalar();
System.out.println("\nCalculating annual salary of a part-time employee:");
partTimeEmployee.computeSalary();
}
}
Analyzation: Given the program below Calculate the annual salary of a full-time employee:
Enter the monthly salary for full-time employee: 20
Annual salary of full-time employee: (a)
import java.util.Scanner;
class Employee {
protected Scanner scanner = new Scanner(System.in);
public static double salary;
}
class FullTimeEmployee extends Employee {
void computeSalar() {
System.out.print("Enter the monthly salary for full-time employee: ");
double monthlySalary = scanner.nextDouble();
salary = monthlySalary * 45;
System.out.println("Annual salary of full-time employee: " + ++salary);
}
}
class PartTimeEmployee extends FullTimeEmployee {
void computeSalary() {
System.out.print("Enter the hourly rate for part-time employee: ");
double hourlyRate = scanner.nextDouble();
System.out.print("Enter the number of hours worked per week: ");
double hoursPerWeek = scanner.nextDouble();
salary = hourlyRate * hoursPerWeek * 4 * 12;
System.out.println("Annual salary of part-time employee: " + ++salary);
}
}
public class Main {
public static void main(String[] args) {
PartTimeEmployee partTimeEmployee = new PartTimeEmployee();
System.out.println("Calculating annual salary of a full-time employee:");
partTimeEmployee.computeSalar();
System.out.println("\nCalculating annual salary of a part-time employee:");
partTimeEmployee.computeSalary();
}
}
What type of inheritance is being applied in the program
Multi level Inheritance
Singel Inheritance
Multiple Inheritance
Hierarchical Inheritance
import java.util.Scanner;
class Employee {
protected Scanner scanner = new Scanner(System.in);
public static double salary;
}
class FullTimeEmployee extends Employee {
void computeSalar() {
System.out.print("Enter the monthly salary for full-time employee: ");
double monthlySalary = scanner.nextDouble();
salary = monthlySalary * 45;
System.out.println("Annual salary of full-time employee: " + ++salary);
}
}
class PartTimeEmployee extends FullTimeEmployee {
void computeSalary() {
System.out.print("Enter the hourly rate for part-time employee: ");
double hourlyRate = scanner.nextDouble();
System.out.print("Enter the number of hours worked per week: ");
double hoursPerWeek = scanner.nextDouble();
salary = hourlyRate * hoursPerWeek * 4 * 12;
System.out.println("Annual salary of part-time employee: " + ++salary);
}
}
public class Main {
public static void main(String[] args) {
}
}
Analyzation : Given the program. How many object im going to create if want to achieve this kind of output.
Calculating annual salary of a full-time employee:
Enter the monthly salary for full-time employee: 14
Annual salary of full-time employee: 631.0
Calculating annual salary of a part-time employee:
Enter the hourly rate for part-time employee: 156
Enter the number of hours worked per week: 2
Annual salary of part-time employee: 14977.0
(a)
class ShapeCalculator {
Scanner scanner = new Scanner(System.in);
}
class CircleCalculator extends ShapeCalculator {
void compute() {
System.out.print("Enter the radius of the circle: ");
double radius = scanner.nextDouble();
double area = 3.14 * radius * radius;
System.out.println("Area of the circle: " + area);
}
}
class RectangleCalculator extends CircleCalculator {
void compute() {
System.out.print("Enter the width of the rectangle: ");
double width = scanner.nextDouble();
System.out.print("Enter the height of the rectangle: ");
double height = scanner.nextDouble();
double area = width * height;
System.out.println("Area of the rectangle: " + area);
}
}
class TriangleCalculator extends RectangleCalculator {
void compute() {
System.out.print("Enter the base of the triangle: ");
double base = scanner.nextDouble();
System.out.print("Enter the height of the triangle: ");
double height = scanner.nextDouble();
double area = 0.5 * base * height;
System.out.println("Area of the triangle: " + area);
}
}
public class Main {
public static void main(String[] args) {
}
}
Analyzation: How many objects im going to create if I want to comput the radius of the circle,width of the rectangle and base of the triangle.
(a)
import java.util.Scanner;
class ShapeCalculator {
Scanner scanner = new Scanner(System.in);
}
class CircleCalculator extends ShapeCalculator {
void compute() {
System.out.print("Enter the radius of the circle: ");
double radius = scanner.nextDouble();
double area = 3.14 * radius * radius;
System.out.println("Area of the circle: " + area);
}
}
class RectangleCalculator extends CircleCalculator {
void compute() {
System.out.print("Enter the width of the rectangle: ");
double width = scanner.nextDouble();
System.out.print("Enter the height of the rectangle: ");
double height = scanner.nextDouble();
double area = width * height;
System.out.println("Area of the rectangle: " + area);
}
}
class TriangleCalculator implements RectangleCalculator {
void compute() {
System.out.print("Enter the base of the triangle: ");
double base = scanner.nextDouble();
System.out.print("Enter the height of the triangle: ");
double height = scanner.nextDouble();
double area = 0.5 * base * height;
System.out.println("Area of the triangle: " + area);
}
}
public class Main {
public static void main(String[] args) {
TriangleCalculator triangleCalculator = new TriangleCalculator();
System.out.println("Calculating area of a circle:");
triangleCalculator.compute();
}
}
Given the program below: What is the out program if the user enter the following details:
Calculating area of a circle:
Enter the base of the triangle: 12
Enter the height of the triangle: 12
Area of the triangle:
(a)
class Vehicle {
void start() {
System.out.println("Vehicle started");
}
}
class Car extends Vehicle {
void start() {
System.out.println("Car started");
}
}
class ElectricCar extends Car {
void start() {
System.out.println("Electric Car started");
}
}
public class Main {
public static void main(String[] args) {
Vehicle myCar = new ElectricCar();
myCar.start();
}
}
Consider the following code snippet: What will be the output of the program?
Vehicle started
Car started
Electric Car started
Error
In the context of inheritance, what is meant by the term "IS-A" relationship?
It implies that a subclass contains all the attributes and methods of the superclass.
It indicates that a subclass can override the methods of the superclass.
It denotes that a subclass can have multiple superclasses.
It means that an object of the subclass can be treated as an object of the superclass.
class Animal {
void eat() {
System.out.println("Animal eats");
}
}
class Dog extends Animal {
void bark() {
System.out.println("Dog barks");
}
}
class BabyDog extends Dog {
void weep() {
System.out.println("BabyDog weeps");
}
}
public class Test {
public static void main(String[] args) {
BabyDog babyDog = new BabyDog();
babyDog.eat();
babyDog.bark();
babyDog.weep();
}
}
What methods can babyDog call?
Only weep()
bark() and weep()
eat() and bark()
eat(), bark(), and weep()
Which of the following best describes hierarchical inheritance in Java?
A class inherits from multiple superclasses.
Multiple superclasses inherit from a single subclass.
A subclass inherits another subclass.
Multiple subclasses inherit from a single superclass.
Java supports multiple inheritance through (a) , allowing a class to implement multiple interfaces.
In Java, the keyword used to inherit properties and methods from one class to another is called the (a) keyword.
Below is the program. How may object im going to create below the main method to compute the radius of the circle, width of the rectangle,base of the triangle.
import java.util.Scanner;
class ShapeCalculator {
Scanner scanner = new Scanner(System.in);
}
class CircleCalculator extends ShapeCalculator {
public void compute1() {
System.out.print("Enter the radius of the circle: ");
double radius = scanner.nextDouble();
double area = 3.14 radius radius;
System.out.println("Area of the circle: " + area);
}
}
class RectangleCalculator extends CircleCalculator {
public void compute2() {
System.out.print("Enter the width of the rectangle: ");
double width = scanner.nextDouble();
System.out.print("Enter the height of the rectangle: ");
double height = scanner.nextDouble();
double area = width * height;
System.out.println("Area of the rectangle: " + area);
}
}
public class Main {
static void compute3() {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the base of the triangle: ");
double base = scanner.nextInt();
System.out.print("Enter the height of the triangle: ");
double height = scanner.nextDouble();
double area = 0.5 base height;
System.out.println("Area of the triangle: " + area);
}
public static void main(String[] args) {
}
}
(a)
Below is the program. How may object im going to create below the main method to compute the radius of the circle, width of the rectangle,base of the triangle.
import java.util.Scanner;
class ShapeCalculator {
Scanner scanner = new Scanner(System.in);
}
class CircleCalculator extends ShapeCalculator {
public void compute1() {
System.out.print("Enter the radius of the circle: ");
double radius = scanner.nextDouble();
double area = 3.14 radius radius;
System.out.println("Area of the circle: " + area);
}
}
class RectangleCalculator extends CircleCalculator {
public void compute2() {
System.out.print("Enter the width of the rectangle: ");
double width = scanner.nextDouble();
System.out.print("Enter the height of the rectangle: ");
double height = scanner.nextDouble();
double area = width * height;
System.out.println("Area of the rectangle: " + area);
}
}
public class Main {
public void compute3() {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the base of the triangle: ");
double base = scanner.nextDouble();
System.out.print("Enter the height of the triangle: ");
double height = scanner.nextDouble();
double area = 0.5 base height;
System.out.println("Area of the triangle: " + area);
}
public static void main(String[] args) {
}
}
(a)
Analyzation : Below is the program. How may object im going to create below the main method to compute the radius of the circle, width of the rectangle,base of the triangle.
import java.util.Scanner;
class ShapeCalculator {
Scanner scanner = new Scanner(System.in);
}
class CircleCalculator extends ShapeCalculator {
public void compute2() {
System.out.print("Enter the radius of the circle: ");
double radius = scanner.nextDouble();
double area = 3.14 radius radius;
System.out.println("Area of the circle: " + area);
}
}
class RectangleCalculator extends CircleCalculator {
public void compute2() {
System.out.print("Enter the width of the rectangle: ");
double width = scanner.nextDouble();
System.out.print("Enter the height of the rectangle: ");
double height = scanner.nextDouble();
double area = width * height;
System.out.println("Area of the rectangle: " + area);
}
public void compute2() {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the base of the triangle: ");
double base = scanner.nextDouble();
System.out.print("Enter the height of the triangle: ");
double height = scanner.nextDouble();
double area = 0.5 base height;
System.out.println("Area of the triangle: " + area);
}
}
public class Main {
public static void main(String[] args) {
}
}
(a)
How many object im going to create below the main method if i want to compute the salary for full time, part time and Contract of Service Employee
import java.util.Scanner;
class Employee {
public Scanner scanner = new Scanner(System.in);
public static double salary = 0;
}
class FullTimeEmployee extends Employee {
void computeSalary() {
System.out.print("Enter the monthly salary for full-time employee: ");
double monthlySalary = scanner.nextDouble();
salary = monthlySalary * 45;
System.out.println("Annual salary of full-time employee: " + salary);
}
}
class PartTimeEmployee extends FullTimeEmployee {
void computeSalary() {
System.out.print("Enter the hourly rate for part-time employee: ");
double hourlyRate = scanner.nextDouble();
System.out.print("Enter the number of hours worked per week: ");
double hoursPerWeek = scanner.nextDouble();
salary = hourlyRate hoursPerWeek 4 * 12;
System.out.println("Annual salary of part-time employee: " + salary);
}
void computeSalary() {
System.out.print("Enter the hourly rate for Contract of Service employee: ");
double hourlyRate = scanner.nextDouble();
System.out.print("Enter the number of hours worked per week: ");
double hoursPerWeek = scanner.nextDouble();
salary = hourlyRate hoursPerWeek 4 * 15;
System.out.println("Annual salary of Contract of Service employee: " + salary);
}
}
public class Main {
public static void main(String[] args) {
}
}
(a)
How many objects im going to create below the main method if i want to compute the salary for part time, contract of service and full time employee
import java.util.Scanner;
class Employee {
public Scanner scanner = new Scanner(System.in);
public static double salary = 0;
}
class FullTimeEmployee extends Employee {
void computeSalary() {
System.out.print("Enter the monthly salary for full-time employee: ");
double monthlySalary = scanner.nextDouble();
salary = monthlySalary * 45;
System.out.println("Annual salary of full-time employee: " + salary);
}
}
class PartTimeEmployee extends FullTimeEmployee {
void computeSalary() {
System.out.print("Enter the hourly rate for part-time employee: ");
double hourlyRate = scanner.nextDouble();
System.out.print("Enter the number of hours worked per week: ");
double hoursPerWeek = scanner.nextDouble();
salary = hourlyRate * hoursPerWeek * 4 * 12;
System.out.println("Annual salary of part-time employee: " + salary);
}
void computeSalaries() {
System.out.print("Enter the hourly rate for Contract of Service employee: ");
double hourlyRate = scanner.nextDouble();
System.out.print("Enter the number of hours worked per week: ");
double hoursPerWeek = scanner.nextDouble();
salary = hourlyRate * hoursPerWeek * 4 * 15;
System.out.println("Annual salary of Contract of Service employee: " + salary);
}
}
public class Main {
public static void main(String[] args) {
}
}
(a)
What is the syntax to create a child. Example is not allowed used the proper term for child and parent.
(a)
import java.util.Scanner;
class Passenger {
String name;
int age;
String flightClass;
double baseFare;
public void getDetails() {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter passenger name: ");
name = scanner.nextLine();
System.out.print("Enter passenger age: ");
age = scanner.nextInt();
scanner.nextLine();
System.out.print("Enter flight class (Economy/Business/First): ");
flightClass = scanner.nextLine();
System.out.print("Enter base fare: ");
baseFare = scanner.nextDouble();
}
public void displayDetails() {
System.out.println("Passenger Name: " + name);
System.out.println("Passenger Age: " + age);
System.out.println("Flight Class: " + flightClass);
System.out.println("Base Fare: " + baseFare);
}
}
class Fare extends Passenger {
double totalFare;
public void calculateFare() {
switch (flightClass) {
case "economy":
totalFare = baseFare;
System.out.println("The total Fare for Economy is : " + ++totalFare);
break;
case "business":
totalFare = baseFare * 1.5;
System.out.println("The total Fare for Economy is : " + totalFare);
break;
case "first":
totalFare = baseFare * 2;
break;
default:
System.out.println("Invalid flight class entered.");
System.out.println("The total Fare for Economy is : "+ totalFare);
totalFare = 0;
break;
}
}
}
public class Main {
public static void main(String[] args) {
Fare fare = new Fare();
System.out.println("Enter passenger details:");
fare.getDetails();
fare.calculateFare();
System.out.println("\nPassenger details are:");
fare.displayDetails();
}
}
Analyzation Given the program example: What is the output if the user enter the following details:
Enter passenger details:
Enter passenger name: Erickson Antonio
Enter passenger age: 30
Enter flight class (Economy/Business/First): first
Enter base fare: 768
The total Fare for Economy is : (a)
import java.util.Scanner;
class Employee {
public Scanner scanner = new Scanner(System.in);
public static double salary = 0;
}
class FullTimeEmployee implements Employee {
void computeSalary() {
System.out.print("Enter the monthly salary for full-time employee: ");
double monthlySalary = scanner.nextDouble();
salary = monthlySalary * 45;
System.out.println("Annual salary of full-time employee: " + salary);
}
}
class PartTimeEmployee implements FullTimeEmployee {
void computeSalary() {
System.out.print("Enter the hourly rate for part-time employee: ");
double hourlyRate = scanner.nextDouble();
System.out.print("Enter the number of hours worked per week: ");
double hoursPerWeek = scanner.nextDouble();
salary = hourlyRate * hoursPerWeek 4 * 12;
System.out.println("Annual salary of part-time employee: " + salary);
}
void computeSalaries() {
System.out.print("Enter the hourly rate for Contract of Service employee: ");
double hourlyRate = scanner.nextDouble();
System.out.print("Enter the number of hours worked per week: ");
double hoursPerWeek = scanner.nextDouble();
salary = hourlyRate * hoursPerWeek 4 * 15;
System.out.println("Annual salary of Contract of Service employee: " + salary);
}
}
public class Main {
public static void main(String[] args) {
FullTimeEmployee p = new FullTimeEmployee();
p.computeSalary();
PartTimeEmployee s = new PartTimeEmployee();
s.computeSalary() ;
s.computeSalaries() ;
}
}
Given the program below. What is the output of the program for the total salary of Contract of Service.
(a)
How many objects im going to create below the main method if i want to see the computation for fulltime, part time, and contrat of Service
import java.util.Scanner;
class Employee {
public Scanner scanner = new Scanner(System.in);
public static double salary = 0;
}
class FullTimeEmployee extends Employee {
void computeSalary() {
System.out.print("Enter the monthly salary for full-time employee: ");
double monthlySalary = scanner.nextDouble();
salary = monthlySalary * 45;
System.out.println("Annual salary of full-time employee: " + salary);
}
}
class PartTimeEmployee extends PartTimeEmployee{
void computeSalary() {
System.out.print("Enter the hourly rate for part-time employee: ");
double hourlyRate = scanner.nextDouble();
System.out.print("Enter the number of hours worked per week: ");
double hoursPerWeek = scanner.nextDouble();
salary = hourlyRate * hoursPerWeek 4 * 12;
System.out.println("Annual salary of part-time employee: " + salary);
}
void computeSalaries() {
System.out.print("Enter the hourly rate for Contract of Service employee: ");
double hourlyRate = scanner.nextDouble();
System.out.print("Enter the number of hours worked per week: ");
double hoursPerWeek = scanner.nextDouble();
salary = hourlyRate * hoursPerWeek 4 * 15;
System.out.println("Annual salary of Contract of Service employee: " + salary);
}
}
public class Main {
public static void main(String[] args) {
}
}
(a)
import java.util.Scanner;
class ShapeCalculator {
Scanner scanner = new Scanner(System.in);
}
class CircleCalculator extends ShapeCalculator {
void compute() {
System.out.print("Enter the radius of the circle: ");
double radius = scanner.nextDouble();
double area = 3.14 * radius * radius;
System.out.println("Area of the circle: " + area);
}
}
class RectangleCalculator implements CircleCalculator {
void compute() {
System.out.print("Enter the width of the rectangle: ");
double width = scanner.nextDouble();
System.out.print("Enter the height of the rectangle: ");
double height = scanner.nextDouble();
double area = width * height;
System.out.println("Area of the rectangle: " + area);
}
}
class TriangleCalculator implements RectangleCalculator {
void compute() {
System.out.print("Enter the base of the triangle: ");
double base = scanner.nextDouble();
System.out.print("Enter the height of the triangle: ");
double height = scanner.nextDouble();
double area = 0.5 * base * height;
System.out.println("Area of the triangle: " + area);
}
}
public class Main {
public static void main(String[] args) {
TriangleCalculator triangleCalculator = new TriangleCalculator();
System.out.println("Calculating area of a circle:");
triangleCalculator.compute();
}
}
What is the Error in the program. Write NO Error if none, If theres an error write the incorrect code and change it with correct answer. Example wrong - int correct - double
(a)
When a subclass is created from a superclass, the relationship is often described using the phrase (a) , indicating that the subclass is a specific type of the superclass.
In (a) inheritance, there is a chain of inheritance where a class is derived from another class, which is also derived from another class.
class Base {
void baseMethod() {
System.out.println("Base method");
}
}
class Derived1 extends Base {
void derived1Method() {
System.out.println("Derived1 method");
}
}
class Derived2 extends Base {
void derived2Method() {
System.out.println("Derived2 method");
}
}
Identify the i TYPE of nheritance pattern used in the given example:
(a)
Determine the type of inheritance shown in this code:
class Alpha {
void alphaMethod() {
System.out.println("Alpha method");
}
}
class Beta extends Alpha {
void betaMethod() {
System.out.println("Beta method");
}
}
class Gamma extends Beta {
void gammaMethod() {
System.out.println("Gamma method");
}
}
(a)
What is the error in the program or What makes the program incorrect.
class Person {
void speak() {
System.out.println("Person speaks");
}
}
class Employee implements Person {
void work() {
System.out.println("Employee works");
}
}
class Manager extends Employee {
void manage() {
System.out.println("Manager manages");
}
}
(a)
