Java Exam Booklet
Java Exam Booklet
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Notes on Arrays in Java
An array is a data structure that allows you to store multiple elements of the same type in a single
variable. It is a container object that holds a fixed number of values of a single type. The length of an
1. Declaration:
`dataType[] arrayName;`
Example:
`int[] numbers;`
2. Allocation:
Example:
3. Initialization:
`arrayName[index] = value;`
Example:
`numbers[0] = 10;`
Multi-dimensional Arrays
Java supports multi-dimensional arrays, which are arrays of arrays.
The most common type is the two-dimensional array, often used to represent a matrix.
Declaration:
Example:
Initialization:
`matrix[0][0] = 1; matrix[0][1] = 2;`
Alternatively:
int[][] matrix = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
System.out.println();
`arrayName.length`
Example:
2. Copying an array:
Using System.arraycopy:
3. Sorting an array:
`Arrays.sort(arrayName);`
`Arrays.binarySearch(arrayName, key);`
Notes on Strings in Java
In Java, strings are objects that represent sequences of characters. The `String` class is used to
create and manipulate strings. Strings are immutable, meaning once a string is created, its value
cannot be changed.
3. String concatenation:
4. Using `String.format`:
// String length
// Accessing characters
// Substring
// String concatenation
4. `indexOf(char/substring)`: Returns the index of the first occurrence of the specified character or
substring.
10. `split(delimiter)`: Splits the string into an array based on the given delimiter.
// Convert to uppercase
// Replace characters
// Check equality
fun"));
`sb.append(" World");`
`System.out.println(sb.toString());`
Notes on Control Statements in Java
Control statements are used to alter the flow of execution in a program. They allow the program to
take decisions, repeat actions, or jump to specific parts of the code. Java provides three types of
control statements:
1. **Decision-Making Statements**
2. **Looping Statements**
3. **Jump Statements**
Decision-Making Statements
1. **if Statement**:
Example:
```java
if (a > b) {
```
2. **if-else Statement**:
Executes one block if the condition is true, another if false.
Example:
```java
if (a > b) {
System.out.println("a is greater");
} else {
System.out.println("b is greater");
```
3. **switch Statement**:
Example:
```java
switch (day) {
```
Looping Statements
1. **for Loop**:
Example:
```java
```
2. **while Loop**:
Example:
```java
int i = 0;
while (i < 5) {
System.out.println(i);
i++;
```
3. **do-while Loop**:
Executes a block of code at least once, then repeats as long as the condition is true.
Example:
```java
int i = 0;
do {
System.out.println(i);
i++;
```
if (i % 2 == 0) {
} else {
Jump Statements
1. **break Statement**:
Example:
```java
if (i == 5) {
break;
System.out.println(i);
```
2. **continue Statement**:
```java
if (i == 5) {
continue;
System.out.println(i);
```
3. **return Statement**:
Example:
```java
return a + b;
```
Java Notes - Theory and Code Examples
Abstraction in Java
1. What is Abstraction?
Abstraction is a process of hiding the implementation details and showing only the essential features
of an object.
- Helps in designing systems where implementation details can change without affecting the code
3. Abstract Classes
- It can have both abstract (without implementation) and concrete (with implementation) methods.
- Example:
```java
void stopEngine() {
System.out.println("Engine stopped.");
Page 1
Java Notes - Theory and Code Examples
void startEngine() {
myCar.startEngine();
myCar.stopEngine();
```
4. Interfaces
- An interface is a reference type in Java, similar to a class, but it can contain only abstract methods
- Example:
```java
interface Animal {
void sound();
Page 2
Java Notes - Theory and Code Examples
System.out.println("Barks");
dog.sound();
```
- A class can implement multiple interfaces but can extend only one abstract class.
6. Real-world Example
```java
void draw() {
System.out.println("Drawing Circle");
Page 3
Java Notes - Theory and Code Examples
void draw() {
System.out.println("Drawing Rectangle");
s1.draw();
s2.draw();
```
- Interface Example:
```java
interface Payment {
void pay();
Page 4
Java Notes - Theory and Code Examples
p1.pay();
p2.pay();
```
Summary:
Page 5
Java Notes - Theory and Code Examples
Inheritance in Java
1. What is Inheritance?
Inheritance is one of the key principles of Object-Oriented Programming (OOP) that allows a class to
- Code Reusability: Common code can be defined in the parent class and reused by child classes.
- Extensibility: New functionality can be added to an existing class without modifying it.
Example:
```java
class Animal {
void eat() {
void bark() {
Page 1
Java Notes - Theory and Code Examples
```
4. Types of Inheritance
- **Multilevel Inheritance**: A class inherits from another class, which in turn inherits from another
class.
```java
class Vehicle {
void start() {
System.out.println("Vehicle started.");
void drive() {
Page 2
Java Notes - Theory and Code Examples
void charge() {
myCar.start();
myCar.drive();
myCar.charge();
```
5. Overriding in Inheritance
Child classes can modify (override) methods defined in the parent class.
Example:
```java
class Animal {
void sound() {
Page 3
Java Notes - Theory and Code Examples
@Override
void sound() {
System.out.println("Cat meows.");
```
The `super` keyword refers to the parent class and is used to:
Example:
```java
class Animal {
void sound() {
Page 4
Java Notes - Theory and Code Examples
void sound() {
System.out.println("Dog barks.");
void displayNames() {
myDog.sound();
myDog.displayNames();
```
Page 5
Java Notes - Theory and Code Examples
8. Real-world Example
```java
class Employee {
String name;
double salary;
void displayDetails() {
String department;
void displayDetails() {
super.displayDetails();
mgr.name = "Alice";
mgr.salary = 75000;
mgr.department = "IT";
mgr.displayDetails();
Page 6
Java Notes - Theory and Code Examples
```
Summary:
- Enables code reusability and makes the code easier to maintain and extend.
Page 7
Polymorphism in Java
Polymorphism in Java refers to the ability of a single interface or method to behave differently in
different contexts.
It allows objects to be treated as instances of their parent class rather than their actual class. This
promotes flexibility,
Polymorphism is a core concept of Object-Oriented Programming (OOP) and is classified into two
main types:
1. Compile-Time Polymorphism
Also known as method overloading, Compile-Time Polymorphism occurs when multiple methods in
the same class share the same name but differ in:
Example:
class Calculator {
// Method with two integer parameters
return a + b;
return a + b + c;
return a + b;
2. Run-Time Polymorphism
Also known as method overriding, Run-Time Polymorphism occurs when a subclass provides a
Key Points:
- The method in the subclass must have the same name, return type, and parameters as the
Example:
class Animal {
void sound() {
@Override
void sound() {
System.out.println("Dog barks");
@Override
void sound() {
System.out.println("Cat meows");
}
myAnimal.sound();
myDog.sound();
myCat.sound();
Benefits of Polymorphism
1. Code Reusability: Common behavior can be reused in different parts of the application.
multitasking.
A thread is a lightweight subprocess, the smallest unit of processing. Java provides built-in support
for
Multithreading enables efficient utilization of CPU resources, allowing multiple tasks to run
2. **Main Thread**: Every Java program starts with the main thread, which is created by the JVM.
4. **Lifecycle of a Thread**: A thread goes through the following states: New, Runnable, Running,
To create a thread by extending the `Thread` class, you need to override its `run()` method, which
Example:
class MyThread extends Thread {
System.out.println("Thread is running...");
To create a thread by implementing the `Runnable` interface, you need to override its `run()` method
Example:
System.out.println("Thread is running...");
}
public class Main {
MyThread(String name) {
threadName = name;
}
public void run() {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
thread1.start();
thread2.start();
Benefits of Multithreading
2. Concurrent Execution: Multiple tasks can run simultaneously, reducing execution time.
3. Simplified Model: Multithreading simplifies program structure for tasks like animations,
4. Resource Sharing: Threads of the same process share resources, making inter-thread
communication easier.
File Handling in Java
File Handling in Java allows developers to create, read, write, and manipulate files in a structured
way.
Java provides the `java.io` and `java.nio` packages to work with files.
File handling is essential for applications that require persistent storage, configuration management,
6. **Scanner**: Reads data from a file using delimiters like spaces or newlines.
1. Creating a File
To create a file, use the `File` class's `createNewFile()` method. It returns `true` if the file is created
successfully.
Example:
import java.io.File;
import java.io.IOException;
try {
if (myFile.createNewFile()) {
} else {
} catch (IOException e) {
e.printStackTrace();
2. Writing to a File
To write to a file, use the `FileWriter` class. You can write data character by character or as a string.
Example:
import java.io.FileWriter;
import java.io.IOException;
public class Main {
try {
writer.close();
} catch (IOException e) {
e.printStackTrace();
To read data from a file, use the `Scanner` or `BufferedReader` class. You can read the file line by
Example:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
while (scanner.hasNextLine()) {
System.out.println(data);
scanner.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
4. Deleting a File
To delete a file, use the `delete()` method of the `File` class. It returns `true` if the file is successfully
deleted.
Example:
import java.io.File;
} else {
2. File Manipulation: Supports operations like reading, writing, renaming, and deleting files.
3. Streamlined Input/Output: Makes it easier to manage input and output for applications.
Swing is a part of Java Foundation Classes (JFC) that is used to create window-based applications.
It is built on
top of the AWT (Abstract Window Toolkit) API and entirely written in Java, making it
platform-independent.
Swing provides a richer set of components and is more flexible compared to AWT.
1. **JFrame**:
2. **JPanel**:
3. **JLabel**:
4. **JButton**:
5. **JTextField**:
6. **JTextArea**:
- JTextArea allows users to input multiple lines of text.
7. **JCheckBox**:
- JCheckBox is a component that represents a check box that can be selected or deselected.
8. **JRadioButton**:
- JRadioButton is used to create radio buttons, which are part of a group where only one button
can be selected.
9. **JComboBox**:
10. **JList**:
11. **JTable**:
- JMenu is used to create menus, while JMenuBar acts as the menu bar container.
13. **JScrollBar**:
Example Code: Creating a Simple Swing Application with JFrame, JLabel, JButton, and
JTextField
import javax.swing.*;
import java.awt.event.*;
frame.setSize(400, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(null);
// Create a JLabel
frame.add(label);
// Create a JTextField
frame.add(textField);
// Create a JButton
frame.add(button);
// Add ActionListener to the button
button.addActionListener(new ActionListener() {
});
frame.setVisible(true);
Swing is a powerful GUI library in Java that provides the tools to create modern, cross-platform
graphical applications.
Its flexibility and extensibility make it a popular choice for desktop application development.
PRIME NUMBERS. Scanner scanner = new Scanner(System.in);
import java.util.Scanner; System.out.print("Enter the starting number (m): ");
int m = scanner.nextInt();
public class PrimeNumbers {
public static void main(String[] args) { System.out.print("Enter the ending number (n): ");
Scanner scanner = new Scanner(System.in); int n = scanner.nextInt();
System.out.print("Enter the starting number (m): "); for (int i = m; i <= n; i++) {
int m = scanner.nextInt(); int num = i;
int sum = 0;
System.out.print("Enter the ending number (n): "); int digits = String.valueOf(i).length();
int n = scanner.nextInt();
while (num != 0) {
for (int i = m; i <= n; i++) { int remainder = num % 10;
if (i <= 1) continue; sum += Math.pow(remainder, digits);
boolean isPrime = true; num /= 10;
}
for (int j = 2; j <= Math.sqrt(i); j++) {
if (i % j == 0) { if (sum == i) {
isPrime = false; System.out.println(i);
break; }
} }
}
scanner.close();
if (isPrime) { }
System.out.println(i); }
}
}
Calculate the Volume of a Sphere
import java.util.*;
scanner.close();
} import java.math.*;
}
class Main
PERFECT NUMBERS.
{
import java.util.Scanner;
public static void main(String args[])
public class PerfectNumbers { {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in); Scanner abc=new Scanner(System.in);
float r=abc.nextFloat();
System.out.print("Enter the starting number (m): ");
int m = scanner.nextInt(); double v=(4f/3f)* Math.PI*Math.pow(r,3);
System.out.print(String.format("%.2f",v));
System.out.print("Enter the ending number (n): ");
int n = scanner.nextInt(); }
int[] girlsAges = new int[N]; b) write a java program to implement access specifiers with the
int[] boysAges = new int[M]; help of packages.
System.out.println("Enter the ages of girls:"); Step 1: Create the com.company package with a class Employee.
for (int i = 0; i < N; i++) {
girlsAges[i] = scanner.nextInt(); package com.company;
}
public class Employee {
System.out.println("Enter the ages of boys:"); public int employeeId;
for (int i = 0; i < M; i++) { public String employeeName;
boysAges[i] = scanner.nextInt();
} private double salary;
person.displayDetails(); System.out.print(a+b);
}
System.out.println("Name: " + person.getName());
System.out.println("Age: " + person.getAge()); }
}
} Time taken for one harmonic motion
import java.util.*;
program that calculates the displacement (s) import java.math.*;
import java.util.*; class Main
class Main {
{ public static void main(String args[])
public static void main(String args[]) {
{ Scanner atz=new Scanner(System.in);
float u,a,t; double g=9.8;
Scanner atz=new Scanner(System.in); double L=atz.nextDouble();
u=atz.nextFloat(); double t=2 * Math.PI * Math.sqrt(L/g);
a=atz.nextFloat(); System.out.printf("%.2f",t);
t=atz.nextFloat(); }
float s=(u*t)+(0.5f *a*(t*t)); }
System.out.print(s);
electricity bill (taking input from the keyboard)
}
import java.util.*;
}
class Main
Simple Interest {
public static void main(String args[]) System.out.print("Hot Weather");
{ }
Scanner sc=new Scanner(System.in); else if(n>=40)
double b=0d; {
int id=sc.nextInt(); System.out.print("Very hot Weather");
int u=sc.nextInt(); }
if(u<=199)
b=u*1.20; else{
else if(u>=200 && u<=399) System.out.print("Invalid input");
b=u*1.50; }
else if(u>=400 && u<=599) scn.close();
b=u*1.80; }
else }
b=u*2.00; Arithmetic Progression(taking input from the
if(b>400) keyboard)
b+=(0.15*b); import java.util.*;
if(b<100) class Main
b=100; {
System.out.print(b); public static void main(String args[])
} {
} Scanner scn=new Scanner(System.in);
case 3: }
break; {
System.out.print("Invalid Choice"); {
} int i,n=s.nextInt();
} for(i=0;i<n;i++)
} {
arr[i][0]=s.next();
Weekly Temperature Analysis (storing arrays)
arr[i][1]=s.next();
import java.util.*;
}
class Main
char[] grades={'A','B','C','D','E'};
{
for(char grade:grades)
public static void main(String args[])
{
{
System.out.println("");
int n=7,i;
System.out.print(grade+":");
double[] t=new double[7];
for(i=0;i<n;i++)
double sum=0.00;
{
Scanner s=new Scanner(System.in);
boolean first=true;
for(i=0;i<n;i++)
if(arr[i][1].charAt(0)==grade)
{
{
t[i]=s.nextDouble();
if(!first)
sum+=t[i];
System.out.print(" ");
}
System.out.print(" "+arr[i][0]);
double max=t[0];
first=false; }
} }
} Employee details (Creating Class & Creating
} ,Implementing Method)
} import java.util.*;
}
if(rn[i]==rollno) System.out.print("Stock
Percentage:"+stockpercentage+"%");
{
}
System.out.println("Roll Number: "+rn[i]+", Name:
"+name[i]+", Marks: "+marks[i]); catch(ArithmeticException e){
found=true; System.out.print(e.getMessage());
break; }
} }
} }
} user2.start();
} user2.join();
user3.start();
return bal; }
} catch (InterruptedException e) {
} e.printStackTrace();
}
{ import java.io.IOException;
outputStream.write(byteData);
public class Main { }
public static void main(String[] args) { System.out.println("File Copied Successfully");
String filePath = "input.txt"; }
int lineCount = 0; catch (IOException e) {
int wordCount = 0; System.out.println("Error: " + e.getMessage());
int charCount = 0; }
}
try (BufferedReader reader = new }
BufferedReader(new FileReader(filePath))) {
reads a file and displays the file on the screen
String line; (BufferedReader)
while ((line = reader.readLine()) != null) { import java.io.BufferedReader;
lineCount++; import java.io.FileReader;
charCount += line.replaceAll("\\s", "").length(); import java.io.IOException;
String[] words = line.trim().split("\\s+");
wordCount += words.length; public class Main {
} public static void main(String[] args) {
System.out.println("Lines: " + lineCount); String filePath = "input.txt";
System.out.println("Words: " + wordCount); try (BufferedReader reader = new
System.out.println("Characters: " + charCount); BufferedReader(new FileReader(filePath))) {
} String line;
catch (IOException e) { int lineNumber = 1;
System.out.println("Error reading file: " + while ((line = reader.readLine()) != null) {
e.getMessage()); System.out.println(lineNumber + ": " + line);
} lineNumber++;
} }
} }
Copying File Contents (FileInputStream & catch (IOException e) {
FileOutputStream)
System.out.println("Error reading file: " +
import java.io.FileInputStream; e.getMessage());
import java.io.FileOutputStream; }
import java.io.IOException; }
}
public class Main { Calculator Using Swings
public static void main(String[] args) { import javax.swing.*;
String sourceFile = "source.txt"; import java.awt.*;
String destinationFile = "destination.txt"; class Main {
public static void main(String[] args) {
try (FileInputStream inputStream = new JFrame frame = new JFrame("Calculator");
FileInputStream(sourceFile);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CL
FileOutputStream outputStream = new OSE);
FileOutputStream(destinationFile)) {
frame.setSize(300, 400);
int byteData;
JPanel panel = new JPanel();
while ((byteData = inputStream.read()) != -1) {
panel.setLayout(new GridLayout(4, 4, 5, 5)); genderGroup.add(femaleButton);
String[] buttons = {
"7", "8", "9", "*", gbc.gridx = 0; gbc.gridy = 0; formPanel.add(new
JLabel("Name:"), gbc);
"4", "5", "6", "/",
gbc.gridx = 1; formPanel.add(nameField, gbc);
"1", "2", "3", "+",
gbc.gridx = 0; gbc.gridy = 1; formPanel.add(new
"0", ".", "=", "-" JLabel("Address:"), gbc);
}; gbc.gridx = 1; formPanel.add(addressField, gbc);
for (String text : buttons) { gbc.gridx = 0; gbc.gridy = 2; formPanel.add(new
JButton button = new JButton(text); JLabel("Gender:"), gbc);
panel.add(button); gbc.gridx = 1; formPanel.add(new JPanel(new
FlowLayout(FlowLayout.LEFT)) {{
}
add(maleButton); add(femaleButton);
frame.add(panel);
}}, gbc);
frame.setVisible(true);
}
add(formPanel, BorderLayout.CENTER);
}
Student details using swings
JPanel buttonPanel = new JPanel();
import javax.swing.*;
JButton saveButton = new JButton("Save"),
import java.awt.*; cancelButton = new JButton("Cancel");
buttonPanel.add(saveButton);
public class Main extends JFrame { buttonPanel.add(cancelButton);
public Main() { add(buttonPanel, BorderLayout.SOUTH);
setTitle("Student Detail");
setSize(300, 200); saveButton.addActionListener(e ->
setDefaultCloseOperation(EXIT_ON_CLOSE); JOptionPane.showMessageDialog(null,
import java.util.*; {
Book b1=new Book();
} {
private int eid;
} }
for(i=0;i<r;i++) }
{
for(j=0;j<c;j++) public String getName() {
{ return name;
arr[i][j]=s.nextInt(); }
} return salary;
}
{ return 0.0;
for(j=0;j<c;j++) }
} }
} }
public Programmer(String name, String address, double
salary, String language) {
class Manager extends Employee {
super(name, address, salary, language);
public Manager(String name, String address, double
salary) { }
super(name, address, salary, "Manager");
} @Override
@Override public double calculateBonus() {
public double calculateBonus() { return getSalary() * 0.12;
return getSalary() * 0.15; }
} @Override
@Override public String generatePerformanceReport() {
public String generatePerformanceReport() { return "Performance report for Programmer " +
getName() + ": Excellent";
return "Performance report for Manager " +
getName() + ": Excellent"; }
} public void debugCode() {
public void manageProject() { System.out.println("Programmer " + getName() + "
is debugging code in Python");
System.out.println("Manager " + getName() + " is
managing a project."); }
} }
}
public class Main {
class Developer extends Employee { public static void main(String[] args) {
private String language; Manager m = new Manager("Raju Dev", "1 ABC St",
80000);
public Developer(String name, String address, double
salary, String language) { Developer d = new Developer("Neeraj Gupta", "2
PQR St", 72000, "Java");
super(name, address, salary, "Developer");
this.language = language; Programmer p = new Programmer("Sujay Raj", "3
ABC St", 76000, "Python");
}
System.out.println("Manager's Bonus: $" +
m.calculateBonus());
@Override public double calculateBonus() { System.out.println("Developer's Bonus: $" +
return getSalary() * 0.10; d.calculateBonus());
} System.out.println("Programmer's Bonus: $" +
p.calculateBonus());
@Override
public String generatePerformanceReport() { System.out.println(m.generatePerformanceReport());
return "Performance report for Developer " + System.out.println(d.generatePerformanceReport());
getName() + ": Good";
System.out.println(p.generatePerformanceReport());
}
m.manageProject();
public void writeCode() {
d.writeCode();
System.out.println("Developer " + getName() + " is
writing code in " + language); p.debugCode();
} }
} }
Parent share to sons and daughter (Inheritance,
class Programmer extends Developer { Encapsulation, Constructor Chaining,
Polymorphism, Aggregation, Arithmetic
Operations, Modularity, Abstraction, Code public Son1(double amt) {
Reusability, Overriding, Scanner, Type Casting, super(amt);
Input Handling, Resource Management, Output }
Formatting, Design Principles.)
}
import java.util.Scanner;
class Son2 extends FM {
public Son2(double amt) {
class FM {
super(amt);
double amt;
}
public FM(double amt) {
this.amt = amt;
public void giveToSister(Daughter daughter) {
}
double toDaughter = this.amt * 0.10;
daughter.addAmount(toDaughter);
public void addAmount(double add) {
this.deductAmount(toDaughter);
this.amt += add;
}
}
}
System.out.println(savingsAccount.accountDetails()); }
System.out.println(); @Override