0% found this document useful (0 votes)
45 views4 pages

Review Questions - Kasun

This document contains review questions and answers for a Java programming exam. It includes multiple choice questions about Java concepts like classes, variables, and layout managers. It also includes short answer questions about GUI programming requirements and using different layout managers. Sample programs are provided to demonstrate switch statements and creating a GUI with text fields and buttons using different layouts.

Uploaded by

Kaz
Copyright
© Attribution Non-Commercial (BY-NC)
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)
45 views4 pages

Review Questions - Kasun

This document contains review questions and answers for a Java programming exam. It includes multiple choice questions about Java concepts like classes, variables, and layout managers. It also includes short answer questions about GUI programming requirements and using different layout managers. Sample programs are provided to demonstrate switch statements and creating a GUI with text fields and buttons using different layouts.

Uploaded by

Kaz
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 4

Review Questions JAVA PROGRAMMING Prepared by, Kasun Fernando

Multiple Choice Questions

1.) class B{ public static void main(String args[]){ boolean b = false; int i = 1; do{ i++; b = !b; }while(b); System.out.println(i); } } Choose the Output? 1) 2 2) 3 3) 1 4) Compile Error 2.) BorderLayout manager positions to place components are; 1) North, South, East, West, Center 2) Up, Down, Left, Right, Middle 3) North, Middle, South, West, East 4) Up, Down, Center, Left, Right 3.) What is the correct way to define a final variable? 1) final a = 5; 2) Final a; a = 5; 3) final int a = 5; 4) final int a; int = 5; 4.) Select the encapsulated variable; 1) public int b; 2) final public int b = 1; 3) private int b; 4) abstract int b; 5.) What is NOT an advantage of encapsulation? 1) Data hiding 2) Immutability 3) Data validation 4) More codes

Short Answer Questions 1.) What are three requirement of the basic model for a GUI program? 2.) Write the code to create a BorderLayout manager?

What is the Output of the Program? 1.) class A{ public static void main(String args[]){ final int a = 3; final ina b; b = 2; int x = 1; switch(x){ case a: System.out.println(A); case b: System.out.println(B); } } }

2.) class A{ public static void main(String args[]){ int x = 3; switch(x){ case 1: System.out.println(A); case 2: System.out.println(B); break; case 3: System.out.println(C); case 4: System.out.println(D); break; default : System.out.println(E); } } }

Write a program Write the code to display the following; Hint: use GridLayout and FlowLayout managers

textBox

buttons

Answers:
MCQ: Q1) 2 Q2) 1 Q3) 3 Q4) 3 Q5) 4 Short Answers: Q1) 1. Declaring application as event listener (action listener) (e.g. implements ActionListener) 2. Register the reactive components (e.g. tFahr.addActionListener (this)) 3. Define the action to be performed (methods) (e.g. action Performed (ActionEvent e)) Q2) BorderLayout layout = new BorderLayout(0, 0); setLayout(layout);

Output 1.) Compile Error 2.) C and D Write the Code

import java.awt.*; class Calc{ public static void main(String args[]){ myCalc m = new myCalc(); System.out.println(); } } class myCalc extends Frame{ myCalc(){ setTitle("myClac"); setSize(300,100); Button b1 = new Button(" 1 "); Button b2 = new Button(" 2 "); Button b3 = new Button("Add"); TextField t = new TextField(20); add(t,BorderLayout.NORTH); Panel p = new Panel(); add(p,BorderLayout.CENTER); GridLayout g = new GridLayout(3,3,2,2); FlowLayout ff = new FlowLayout(); p.setLayout(ff); p.add(b1); p.add(b2); p.add(b3); setVisible(true); } }

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy