0% found this document useful (0 votes)
4 views5 pages

OOPS 15 Mark

The document outlines various topics in Object Oriented Programming using Java, including constructors, iteration statements, method overloading, packages, inheritance, exception handling, file I/O, event listeners, mouse events, multithreading, AWT menu bars, inter-thread communication, and wrappers with auto-boxing. It provides example programs and references specific sections in the provided notes for detailed explanations. Each topic is designed to enhance understanding of Java programming concepts and their practical applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

OOPS 15 Mark

The document outlines various topics in Object Oriented Programming using Java, including constructors, iteration statements, method overloading, packages, inheritance, exception handling, file I/O, event listeners, mouse events, multithreading, AWT menu bars, inter-thread communication, and wrappers with auto-boxing. It provides example programs and references specific sections in the provided notes for detailed explanations. Each topic is designed to enhance understanding of Java programming concepts and their practical applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

CS3391- Object Oriented Programming

PART B & C
1. a)Write detailed notes on Constructor with suitable example program.
Refer 1.11.1 & 1.11.2 in given notes.

2. Summarize the Java’s Iteration statements with an example program.


(Nov/Dec-2022)
Refer 1.9 /page no. 42 in given notes.

3. Explain method overloading with example.


Refer 2.1 in given notes.

4. Design a java program with Constructor with suitable explanations

class Main {
private String name;

// constructor
Main() {
System.out.println("Constructor Called:");
name = "Programiz";
}

public static void main(String[] args) {

// constructor is invoked while


// creating an object of the Main class
Main obj = new Main();
System.out.println("The name is " + obj.name);
}
}

Output:
Constructor Called:
The name is Programiz

5. What is Package? Explain in detail about how the packages provide access control to
various categories of visibility for class members.

Refer 2.11 / page no. 44(Unit -2) in given notes.


6. Elaborate the basics of inheritance in java and explain any two inheritance mechanisms
in java.
Refer page no.2.4 in given notes.

7. Explain StringBuffer class with example.


Refer page no. 4.11 in given notes.

8. Explain in detail about Java’s Built-in Exception. Explain any three exceptions
Refer page no.3.5.1 in given notes.

9. Explain in detail about File handling I/O in Java


Refer page no.4.3 in given notes.

10. Discuss about the commonly used event listener interfaces with suitable example
programs. Refer page no.5.2.2 in given notes.

11. Write a java program to demonstrate mouse event handlers and appraise the program
with working procedure in detail.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class MouseEventDemo extends JFrame {
private static final int WIDTH = 600;
private static final int HEIGHT = 400;
// A panel to draw on and capture mouse events
private class DrawingPanel extends JPanel {
private int x = -1, y = -1;
public DrawingPanel() {
// Add mouse listeners for handling events
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
x = e.getX();
y = e.getY();
repaint(); // Request to redraw the panel
}
@Override
public void mousePressed(MouseEvent e) {
x = e.getX();
y = e.getY();
repaint(); } @Override
public void mouseReleased(MouseEvent e) {
x = -1; // Reset coordinates on release
y = -1;
repaint();
}
});
addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent e) {
x = e.getX();
y = e.getY();
repaint();
}
});
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
if (x != -1 && y != -1) {
g.setColor(Color.RED);
g.fillOval(x - 10, y - 10, 20, 20); // Draw a circle at the mouse position
}
}
}
public MouseEventDemo() {
setTitle("Mouse Event Demo");
setSize(WIDTH, HEIGHT);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
// Add the drawing panel to the frame
add(new DrawingPanel());
}
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
MouseEventDemo frame = new MouseEventDemo();
frame.setVisible(true);
});
}
}

12. Construct a java program that implements the concept of multithreading programming

public class MultiThreadingDemo {


// A class that extends Thread to define a custom thread
static class NumberPrinter extends Thread {
private int start;
private int end;
private int delay;

public NumberPrinter(int start, int end, int delay) {


this.start = start;
this.end = end;
this.delay = delay;
}

@Override
public void run() {
for (int i = start; i <= end; i++) {
System.out.println(Thread.currentThread().getName() + " - Number: " + i);
try {
Thread.sleep(delay); // Pause for the specified delay
} catch (InterruptedException e) {
System.err.println("Thread was interrupted: " + e.getMessage());
}
}
}
}

public static void main(String[] args) {


// Creating thread instances with different ranges and delays
Thread thread1 = new NumberPrinter(1, 5, 1000); // Numbers 1 to 5, 1-second delay
Thread thread2 = new NumberPrinter(6, 10, 500); // Numbers 6 to 10, 0.5-second delay
Thread thread3 = new NumberPrinter(11, 15, 2000); // Numbers 11 to 15, 2-second delay

// Start the threads


thread1.start();
thread2.start();
thread3.start();

// Optionally, wait for all threads to finish before exiting the program
try {
thread1.join();
thread2.join();
thread3.join();
} catch (InterruptedException e) {
System.err.println("Main thread was interrupted: " + e.getMessage());
}

System.out.println("All threads have finished executing.");


}
}
13. Explain in detail about java AWT Menu Bars and Menu Items
Refer page no.5.6 in given notes.
14. Explain in detail about Inter-thread Communication.

Refer page no.3.11 in given notes.


15. Explain in detail about Wrappers and Auto-Boxing.
Refer page no.3.13 & 3.14 in given notes.

You might also like