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

Practise Questions 1

1. The document contains questions related to OOP concepts in Java like classes, objects, constructors, interfaces, abstract classes, exceptions and event handling. 2. It asks to create classes for different scenarios like vehicle sales, banking transactions, calculators etc. using these concepts. 3. Questions also involve creating GUI applications using Swing/AWT for tasks like number conversion, calculator etc. and explaining concepts of layouts, events and exceptions.

Uploaded by

yousuf don
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)
37 views5 pages

Practise Questions 1

1. The document contains questions related to OOP concepts in Java like classes, objects, constructors, interfaces, abstract classes, exceptions and event handling. 2. It asks to create classes for different scenarios like vehicle sales, banking transactions, calculators etc. using these concepts. 3. Questions also involve creating GUI applications using Swing/AWT for tasks like number conversion, calculator etc. and explaining concepts of layouts, events and exceptions.

Uploaded by

yousuf don
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

Question 1

1. Write a class with name YOUR_NAME , having two public data members MyName(String
type) and id (int type)
2. Default constructor initializes MyName to YZ and id to be 100.
3. Parameterized constructor initializes MyName and id , when we create it’s
objects.
4. UpdateData(string s, int i) sets MyName and id to s and i respectively
5. YOUR_NAME class also has two public function members PRINTNAME() which
print it’s MyName data member and PRINTID() which prints it’s id
6. Show Details() is another function which will call PRINTNAME() and PRINTID()
functions in it. 7. In main make objects of Your_NAME using constructors as :

Object Name MyName ID

X xxx 200

Y yyy 300

8. Update details of y with your actual name and id


9. Call ShowDetails() by both X and Y objects
10. Write the output

Question2 Design the following GUI


Question3 :
Short questions
1. Can we define private and protected modifiers for data members (fields) in interface
2. Can an interface implement another interface?
3. Identify the errors in following

Question 4:
Create a banking system based on account types using concepts of interfaces. Create an interface
named “bankaccount” that has two methods, deposit and withdraw. Create two classes and name
them as “CurrentAccount” and “SavingAccount”. The classes will consist of two variables,
AccountTitle and AccountBalance. Both the classes will implement the methods defined in
interface to perform a transaction. Create a main class which contains main method. In main
method create object for account types and perform the transaction (deposit and withdraw)

Question5:
Dividing by zero is an operation that has no meaning in ordinary arithmetic and is therefore,
undefined. In programming, however, while it is often associated with an error, that is not
always the case. Show that exception with code.
Question 6:
Create a vehicle sale system based on concept of abstract class. Create a class named “Vehicle”
as abstract class. Vehicle information contains vehicle name, engine cc, manufacturer and model
year. It contains two abstract functions, insertVehicleInfo and displayVehicleInfo. Create
another class named “Owner” which extends the abstract class. The owner information consists
of owner name, CNIC number and contact number. Override the methods defined in abstract
class. Take all information from user and display the complete info of owner and vehicle he/she
bought.
Create a main class which contains main method. In main method create object for child class
and display the information

Question7:
Write GUI for the following form with size 500 x 500. On click of buttons, the text should
appear, e.g on click of 1, 1 will be printed on textField

Q8 Short questions
1. What is abstract class in java? Can we define any method in an abstract class?
2. Describe interface in java. What happens if the class which implements the interface
doesn’t override all methods defined in interface?
3. Describe the AWT class/ library used in java GUI?
Q9 Explain the following
1. Shortly explain the Swing class of Java. Why it is essential in GUI designs?
2. Shortly describe the Grid layout and flow Layout. Name the default layout used in
JFrame and JPanel.
3. In JFrame, setDefaultCloseOperation is used to define the operation when user clicked on
close button in title bar. What options are present in Java for this and how they work?

Q10. Suppose a system that keeps record of Files. This system deals with two types of files. i.e.
Image File and Vide File. For this system, define an abstract class name “File System” which
consists of three variables: name, width and height. It also has two abstract method named
“EnterFile Detail” and “DisplayFileDetail”. Create two class named as “ImageFile” and
“VideoFile”. Image file consists of a variable named bit per pixel and video file consists two
variables: frame per second and duration. Both classes will extend to abstract class and provides
definition of defined abstract methods. Create a main class with main method and create objects
of both classes along with calling both the methods defined in the classes.

Q11. Create a calculator system based on calculator types using concept of interfaces. Create an
interface named “Calculator” that has four methods: sum, subtract, multiplication and division.
Create another interface named “ScientificCalculator: which consists of three methods, sine,
cosine and tangent. The interface will also extend Calculator interface. Create a class and name it
as “CalculatorImplementation: which will implement all the methods defined in interfaces.
Note: for arithmetic operations, two values are needed and for scientific operation only the angle
is required.
Create a main class which contain main method. In main method, create object for the class and
perform the calculator operations

Q12. Shortly explain any four types of exceptions. How exceptions are handled in java.?

Q13 Define event? What is meant by event handling in java?

Q14 Look at the Frame below. Write a GUI program call JavaDaysConverter to convert number
of days to number of hours, number of minutes and number of seconds. User will enter the value
as number of days and then on button click, it will convert into hours, minutes and seconds

You might also like