0% found this document useful (0 votes)
0 views9 pages

All Java Topics 10 Questions Each

The document outlines various programming concepts and tasks related to classes, methods, constructors, inheritance, polymorphism, method overriding, access modifiers, variable types, scopes, abstract classes, interfaces, encapsulation, AWT components, event handling, threads, and their life cycle. Each section contains specific instructions for creating classes, implementing methods, and demonstrating key programming principles. The content serves as a comprehensive guide for understanding and applying object-oriented programming techniques.

Uploaded by

EARNING FACTS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views9 pages

All Java Topics 10 Questions Each

The document outlines various programming concepts and tasks related to classes, methods, constructors, inheritance, polymorphism, method overriding, access modifiers, variable types, scopes, abstract classes, interfaces, encapsulation, AWT components, event handling, threads, and their life cycle. Each section contains specific instructions for creating classes, implementing methods, and demonstrating key programming principles. The content serves as a comprehensive guide for understanding and applying object-oriented programming techniques.

Uploaded by

EARNING FACTS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Classes and Objects

1. Create a class named Student with fields name, age and rollNumber.

2. Instantiate two objects of the Student class.

3. Create a method in Student class to display student info.

4. Create a class named BankAccount with deposit and withdraw methods.

5. Implement a class Library with books as an array.

6. Create a class Mobile with attributes brand, model and price.

7. Instantiate Mobile class using a constructor.

8. Create a class Rectangle with methods to calculate area and perimeter.

9. Implement a class Employee with a method to calculate bonus.

10. Create a class Book with static variable for total books.

Methods
1. Write a method to calculate the factorial of a number.

2. Create a method to reverse a string.

3. Implement a method to check if a number is prime.

4. Write a method to find the maximum of three numbers.

5. Create a method to convert Celsius to Fahrenheit.

6. Write a method to check if a number is even or odd.

7. Implement a method to find the sum of an array.

8. Create a method to count vowels in a string.

9. Write a method to print Fibonacci series up to n terms.

10. Create a method to find the greatest common divisor (GCD) of two numbers.

Constructors and its types


1. Create a class with a default constructor.

2. Create a class with a parameterized constructor.

3. Create a copy constructor for a class.


4. Demonstrate constructor overloading.

5. Initialize an object using parameterized constructor.

6. Use constructor to set default values.

7. Copy one object's data to another using copy constructor.

8. Show difference between default and parameterized constructor.

9. Demonstrate constructor chaining.

10. Create multiple constructors and initialize different sets of variables.

Method Overloading
1. Create overloaded methods for addition with 2 and 3 integers.

2. Overload a method with different data types (int, double).

3. Write overloaded constructors for a Book class.

4. Create an overloaded printDetails method with different parameters.

5. Overload a method to calculate area of square and rectangle.

6. Demonstrate method overloading with different parameter orders.

7. Overload a greet method with/without name parameter.

8. Overload a constructor using this() to reuse code.

9. Overload a method with same name but varying return types.

10. Show compile-time error with invalid method overloading.

Inheritance and its Types


1. Implement single inheritance using Animal and Dog classes.

2. Demonstrate multilevel inheritance using Animal -> Mammal -> Dog.

3. Implement hierarchical inheritance with one base and multiple derived classes.

4. Create a class hierarchy for Shape -> Circle/Rectangle/Triangle.

5. Add constructors in parent and child classes.

6. Override a method from parent class in the child class.

7. Use super keyword to access parent method.


8. Show constructor chaining in inheritance.

9. Implement protected access in inheritance.

10. Create a base class Person and derived classes Student and Teacher.

Polymorphism and its Types


1. Show compile-time polymorphism using method overloading.

2. Demonstrate runtime polymorphism using method overriding.

3. Create a parent class Shape with draw method and override it.

4. Use upcasting to access child class via parent class reference.

5. Use instanceof to check object type.

6. Show late binding with overridden methods.

7. Demonstrate dynamic dispatch using polymorphism.

8. Add multiple overloaded methods and test them.

9. Override equals() method in a custom class.

10. Demonstrate polymorphism in real-life scenario like payment method.

Method Overriding
1. Override a method from base class in derived class.

2. Call overridden method using super keyword.

3. Create Animal class and override makeSound in Dog and Cat.

4. Demonstrate @Override annotation.

5. Use method overriding in toString().

6. Override a method and change its behavior.

7. Compare behavior of overridden and non-overridden methods.

8. Prevent overriding using final keyword.

9. Call parent and child method with same name.

10. Use dynamic method dispatch to invoke overridden method.


Access Modifiers
1. Demonstrate public access modifier.

2. Use private variable with public getter and setter.

3. Access protected member in subclass.

4. Try accessing default modifier across packages.

5. Show error accessing private members from other class.

6. Use public method to access private fields.

7. Demonstrate package-level access.

8. Compare all four access modifiers in a table.

9. Create a class with all types of modifiers.

10. Use access modifier in constructor.

Types of Variables
1. Declare and use a local variable.

2. Create instance variables and access them through object.

3. Use a static variable to count object instances.

4. Compare instance and static variable behavior.

5. Initialize local variable and show its scope.

6. Access static variable without object.

7. Change static variable via one object, observe effect on another.

8. Use final with variables.

9. Create constants using static final.

10. Show default values of instance variables.

Scope of Variables
1. Demonstrate variable inside a method.

2. Access instance variable from constructor.

3. Access static variable globally.


4. Create block scope variable.

5. Declare class-level vs method-level variables.

6. Shadow a variable inside method.

7. Use local variable in loop.

8. Show variable scope in nested blocks.

9. Demonstrate scope using nested methods.

10. Access outer class variable in inner class.

Abstract Classes
1. Create an abstract class and extend it.

2. Add abstract and concrete methods in same class.

3. Extend abstract class and override its method.

4. Instantiate abstract class using subclass.

5. Prevent instantiation of abstract class.

6. Use abstract class as type reference.

7. Create abstract class hierarchy.

8. Override multiple methods from abstract class.

9. Show error when not overriding abstract methods.

10. Use abstract keyword with class and methods.

Interfaces
1. Define a simple interface and implement it.

2. Create interface with multiple abstract methods.

3. Use implements keyword with interface.

4. Access interface constants.

5. Create a class that implements multiple interfaces.

6. Extend one interface from another.

7. Use default method in interface.


8. Use static method in interface.

9. Demonstrate functional interface.

10. Use interface reference to access implemented object.

Multiple Inheritance using Interface


1. Create two interfaces and one class implementing both.

2. Handle method conflict between interfaces.

3. Use multiple inheritance to simulate diamond problem.

4. Demonstrate resolution using default methods.

5. Use interface to access implemented methods.

6. Implement common method from multiple interfaces.

7. Call default method explicitly.

8. Use static method from both interfaces.

9. Show compile-time error without resolving method conflict.

10. Inherit interface and override common methods.

Encapsulation
1. Create private variables with public getter and setter.

2. Hide internal data using encapsulation.

3. Use encapsulation in Employee class.

4. Protect data using accessors and mutators.

5. Restrict direct access to class members.

6. Change internal implementation without affecting users.

7. Create a bank class with balance encapsulated.

8. Use validation in setter methods.

9. Encapsulate a Student class data.

10. Demonstrate advantage of encapsulation.


AWT and Components
1. Create a basic AWT frame using Frame class.

2. Add Button to AWT Frame.

3. Add Label to a Frame.

4. Create TextField and add to Frame.

5. Use CheckboxGroup and display selected value.

6. Add multiple components in FlowLayout.

7. Use GridLayout for component arrangement.

8. Handle window closing using WindowAdapter.

9. Add Choice dropdown to Frame.

10. Add Scrollbar to Frame and handle scroll.

Event Handling
1. Handle button click using ActionListener.

2. Handle text field event.

3. Create window closing event.

4. Use MouseListener to detect clicks.

5. Handle keyboard events using KeyListener.

6. Use ItemListener with Checkbox.

7. Use FocusListener to track focus changes.

8. Change label text on button click.

9. Capture mouse drag and draw.

10. Implement multiple listeners on a component.

Event Delegation Model


1. Demonstrate event source, listener, and event object.

2. Use ActionListener to perform task.

3. Add multiple listeners to one source.


4. Use anonymous inner class for listener.

5. Use adapter classes for partial implementation.

6. Create a GUI with multiple buttons and actions.

7. Demonstrate registration and handling process.

8. Handle key press event and show text.

9. Show event delegation flow.

10. Log events on different user actions.

Threads
1. Create thread using Thread class.

2. Create thread using Runnable interface.

3. Start and stop a thread.

4. Print numbers using threads.

5. Create thread that prints current time.

6. Demonstrate thread sleep().

7. Use thread join().

8. Set thread priority and observe behavior.

9. Name threads and print names.

10. Run multiple threads concurrently.

Thread Life Cycle


1. Show new, runnable and terminated state of thread.

2. Use start() to begin thread execution.

3. Use sleep() and observe TIMED_WAITING state.

4. Demonstrate wait() and notify().

5. Show BLOCKED state using synchronized block.

6. Show WAITING state by waiting on object lock.

7. Monitor thread life using isAlive().


8. Transition thread from waiting to runnable.

9. Show thread priority change in lifecycle.

10. Print each state using thread methods.

Creating Threads
1. Extend Thread class and override run().

2. Implement Runnable and pass to Thread.

3. Create thread by anonymous Runnable class.

4. Use lambda to create Runnable.

5. Start multiple threads with loops.

6. Create and execute thread from main().

7. Stop thread using a flag variable.

8. Pass data to thread constructor.

9. Share resource between threads.

10. Synchronize threads for data consistency.

You might also like