wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JAVA PROGRAMMING EXAM BSAIT 1-2

Total questions: 54

Worksheet time: 2hrs 41mins

Name
Class
Date
1.

What is inheritance in Java?

a)

A mechanism where one object modifies properties and behaviors of a parent object

b)

A mechanism where one object creates properties and behaviors of a parent object

c)

A mechanism where one object loses properties and behaviors of a parent object

d)

A mechanism where one object acquires properties and behaviors of a parent object

2.

What does the 'extends' keyword indicate in Java?

a)

Creating a new class that is a copy of an existing class

b)

Creating a new class that replaces an existing class

c)

Creating a new class that is unrelated to any existing class

d)

Creating a new class that derives from an existing class

3.

What is the superclass in Java inheritance?

a)

The class being inherited from

b)

A class that is a copy of another class

c)

The class that inherits from another class

d)

A class that is unrelated to any other class

4.

What types of inheritance are supported in Java?

a)

Single, hybrid, and hierarchical

b)

Single, multiple, and hybrid

c)

Single, multilevel, and hierarchical

d)

Single, multilevel, and hybrid

5.

What is the relationship between Programmer and Employee classes?

a)

Programmer IS - A Employee

b)

Programmer IS - NOT A Employee

c)

Programmer IS - EQUAL TO Employee

d)

Programmer IS - LIKE A Employee

6.

What is an example of single inheritance in Java?

a)

Dog class inherits the Cat class

b)

Cat class inherits the Dog class

c)

Dog class inherits the Animal class

d)

Animal class inherits the Dog class

7.

What is an example of multilevel inheritance in Java?

a)

BabyDog class inherits the Dog class which inherits the Animal class

b)

Dog class inherits the Animal class

c)

Cat class inherits the Animal class

d)

Animal class inherits the Dog class

8.

What is an example of hierarchical inheritance in Java?

a)

Dog and Cat classes inherit the Animal class

b)

Dog class inherits the Animal class

c)

Cat class inherits the Animal class

d)

Animal class inherits the Dog and Cat classes

9.

How is multiple and hybrid inheritance supported in Java?

a)

Through inheritance only

b)

Through interface only

c)

Through classes only

d)

Through abstract classes only

10.

What does the 'extends' keyword do in Java inheritance?

a)

Changes the functionality of a class

b)

Does not affect the functionality of a class

c)

Decreases the functionality of a class

d)

Increases the functionality of a class

11.

Which term best describes polymorphism in Java?

a)

Singular form

b)

Consistent code

c)

Static method

d)

Single method rendering

e)

Dynamic operation

12.

What is one of the primary benefits of polymorphism in Java?

a)

Increased code inconsistency

b)

Enhanced program complexity

c)

Code reusability

d)

Static method execution

e)

Performance optimization

13.

What challenge does polymorphism in Java introduce to code development?

a)

Reduced flexibility

b)

Simplified maintenance

c)

Increased performance

d)

Enhanced readability

e)

Potential code complexity

14.

What is a potential drawback of polymorphism in Java?

a)

Decreased program flexibility

b)

Reduced code reuse

c)

Simplified debugging process

d)

Increased performance efficiency

e)

Dynamic method binding overhead

15.

Which statement best summarizes the role of polymorphism in Java programming?

a)

It hinders code maintenance and extension.

b)

It simplifies object interactions by enforcing strict type hierarchies.

c)

It allows for the creation of consistent code through shared interfaces.

d)

It eliminates the need for method overloading in object-oriented design.

e)

It prioritizes performance optimization over code flexibility.

16.

Which term best describes the concept of inheritance in Java?

a)

Code encapsulation

b)

Property acquisition

c)

Method overloading

d)

Data abstraction

e)

Object instantiation

17.

What is the relationship between the subclass and superclass in Java inheritance?

a)

Subclass IS-A superclass

b)

Subclass HAS-A superclass

c)

Subclass IMPLEMENTS superclass

d)

Subclass ENCAPSULATES superclass

e)

superclass EXTENDS subclass

18.

Which type of inheritance involves a chain of inheritance?

a)

Single inheritance

b)

Multilevel inheritance

c)

Hierarchical inheritance

d)

Hybrid inheritance

e)

Multiple inheritance

19.

In Java, how is multiple inheritance achieved?

a)

Through the extends keyword

b)

Through the implements keyword

c)

Through the super keyword

d)

Through the extends and implements keywords together

e)

Multiple inheritance is not directly supported in Java

20.

What does the phrase "Programmer IS-A Employee" signify in Java inheritance?

a)

Programmer class has an instance of Employee class

b)

Employee class has an instance of Programmer class

c)

Programmer class inherits from Employee class

d)

Employee class inherits from Programmer class

e)

Programmer class and Employee class are unrelated

21.

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()?

a)

Instance Method Called

b)

Static Method Called

c)

Compile-time error

d)

Runtime error

22.

Which of the following statements is true about static methods in Java?

a)

Static methods can only access static data members and static methods of the same class.

b)

Static methods can access both static and non-static data members and methods of the same class.

c)

Static methods can only be called after creating an instance of the class.

d)

Static methods cannot be overloaded.

23.

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();

}

}

a)

"Instance Method" is printed

b)

The program is correct but no output

c)

The program is Error

24.

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)  

25.

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();

}

}

a)

Public method called

Static method called

b)

No output but the program is correct

c)

The syntax of object is incorrect

d)

The syntax of syntax of calling a method is incorrect

26.

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)  

27.

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)  

28.

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();

}

}

28.

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)  

29.

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();

}

}

29.

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)  

30.

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();

}

}

30.

What type of inheritance is being applied in the program

a)

Multi level Inheritance

b)

Singel Inheritance

c)

Multiple Inheritance

d)

Hierarchical Inheritance

31.

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) {

}

}

31.

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)  

32.

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) {

}

}

32.

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)  

33.

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();

}

}

33.

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)  

34.

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();

}

}

34.

Consider the following code snippet: What will be the output of the program?

a)

Vehicle started

b)

Car started

c)

Electric Car started

d)

Error

35.

In the context of inheritance, what is meant by the term "IS-A" relationship?

a)

It implies that a subclass contains all the attributes and methods of the superclass.

b)

It indicates that a subclass can override the methods of the superclass.

c)

It denotes that a subclass can have multiple superclasses.

d)

It means that an object of the subclass can be treated as an object of the superclass.

36.

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?

a)

Only weep()

b)

bark() and weep()

c)

eat() and bark()

d)

eat(), bark(), and weep()

37.

Which of the following best describes hierarchical inheritance in Java?

a)

A class inherits from multiple superclasses.

b)

Multiple superclasses inherit from a single subclass.

c)

A subclass inherits another subclass.

d)

Multiple subclasses inherit from a single superclass.

38.

Java supports multiple inheritance through (a)   , allowing a class to implement multiple interfaces.

39.

In Java, the keyword used to inherit properties and methods from one class to another is called the (a)   keyword.

40.

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)  

41.

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)  

42.

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)  

43.

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)  

44.

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)  

45.

What is the syntax to create a child. Example is not allowed used the proper term for child and parent.

(a)  

46.

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();

}

}

46.

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)  

47.

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() ;

}

}

47.

Given the program below. What is the output of the program for the total salary of Contract of Service.

(a)  

48.

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)  

49.

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();

}

}

49.

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)  

50.

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.

51.

In (a)   inheritance, there is a chain of inheritance where a class is derived from another class, which is also derived from another class.

52.

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)  

53.

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)  

54.

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)