Sunteți pe pagina 1din 34

1Question Text Which of the following is NOT a component of a window created using the JFrame class? Options 1.

Title bar 2. Menu bar 3. Dialog box 4. Resizable border

Correct Answer: -> 3

2Question Text Consider the following statements: Statement A: A NullPointerException is generated when an object is used without first allocating memory to it. Statement B: You can create exception classes in Java by extending the class Exception. Statement C: A division by zero generates an ArrayOutOfBoundsException. Statement D: An object that has not been allocated memory holds a null value. Which of the given statements are true? Options 1. A, B, and C 2. B, C, and D 3. A, C, and D 4. A, B, and D

Correct Answer: -> 4

3Question Text Consider the following code snippet: Public void run() { while(ClockThread ! = null) { repaint(); try { ClockThread.sleep(1000); } catch (Interruptedexception e) { //This threads sleep was interrupted by another thread } } } public void paint (Graphics g) { String strTime; Date time = new Date(); GregorianCalendar calendar = new GregorianCalendar(); calendar.setTime (time); strTime = calendar.get(Calendar.HOUR) + ; + calendar.get(Calendar.MINUTE) + ; + calendar.get(Calendar.SECOND) ; g.drawstring(strTime,5,10); } What does the above code do? Options

1. 2. 3. 4.

The above code continuously updates the time on the screen. The run() method repaints the screen after every 100 milliseconds. The repaint() method obtains the current time, extracts the hours, minutes, and seconds, converts them into a string, and displays the string on the screen. The above code does not update the time on the screen. The above code continuously updates the time on the screen.The run() method repaints the screen after every 1000 milliseconds. The repaint() method obtains the current time, extracts the hours, minutes, and seconds, converts them into a string, and displays the string on the screen. In this code, the repaint() method obtains the current time, extracts the hours, converts them into a string, and displays the string on the screen.

Correct Answer: -> 3

4Question Text With reference to the start() method, which one of the following statements does not hold true?

Options 1. The start() method starts a thread. 2. The thread enters the runnable state after invoking the start() method. 3. The run() method invokes the start() method. 4. The start() method allocates the system resources that are necessary for the thread.

Correct Answer: -> 3

5Question Text

Which of the following applications provides a remote login? Options 1. FTP 2. HTTP 3. Telnet 4. POP

Correct Answer: -> 3

6Question Text Allen, a programmer with Fusion solutions, wants to access his mailbox that is located on a remote system. Which of the following should he use? Options 1. Telnet 2. FTP 3. SMTP 4. POP

Correct Answer: -> 4

7Question Text Consider the following statements: Statement A: A record in a data file contains only one field. Statement B: A field has two components, field name and field content. Which of the following is true for the above statements? Options 1. Statement A is True and Statement B is False. 2. Statement A is False and Statement B is True. 3. Both Statements A and B are true. 4. Both Statements A and B are false.

Correct Answer: -> 2

8Question Text Number of bytes occupied by "string data type" is: Options 1. 2 2. variable length 3. 8 4. 4

Correct Answer: -> 2

9Question Text Which access specifier allows a class to expose its member variables and member functions to other functions and objects? Options 1. private 2. internal 3. protected internal 4. friend

Correct Answer: -> 2

10Question Text Give the output of the following program: using System; sealed class a { public abstract void one() { Console.WriteLine("you are in sealed class"); } } class inherit_demo1 { public static void Main() { a obj = new a(); obj.one(); }

} Options 1. It will display a message "you are in sealed class". 2. No message will be displayed. The program will give error because a.one() can't be declared with a body since it is 3. marked abstract. 4. Sealed is an unrecognized keyword.

Correct Answer: -> 3

11Question Text Mr. Joe wants to store the details of all the employees. He does so using the following class definition: class emp { string e-name; int e-id; void accept-details() {} void display-details() {} } However, the above class definition is wrong. Give the correct class definition. Options 1. class emp { { string name; int eid; void accept_details[] {}

void display_details() {} } } class emp { { void accept_details() { string name; int eid; 2. } void display-details() { string name; int eid; } } } class emp { string e_name; int e_id; 3. void accept_details() {} void display_details() {} } class emp { void accept_details() { string name; int eid; 4. } void display_details() { string name; int eid; } } Correct Answer: -> 3

12Question Text The statement int[]s ={0,1,2,3,4} states the initialization of an array of size 5. Which of the following statement refers to the same? Options 1. int []s = new int [4] = {0,1,2,3,4} 2. int [] s = new int[4] {0,1,2,3,4} 3. int [] s = new int[5] = {0,1,2,3,4} 4. int [] s = new int[5] {0,1,2,3,4}

Correct Answer: -> 4

13Question Text

Consider the following code that is written to abort a thread but is not able to abort the child thread,why? Give reason. using System; using System.Threading; namespace ThreadSample { class Thred_demo1 { public static void Child() { try { Console.WriteLine("Child thread started"); Console.WriteLine ("Child thread - counting to 10"); for (int i = 0; i < 10; i++) { Thread.Sleep(500); Console.Write("{0}...", i); } Console.WriteLine("Child thread finished"); } catch (ThreadAbortException e) { Console.WriteLine("Exception"+e); } finally { Console.WriteLine ("Child thread -Unable to catch the exception."); } } public static void Main() { ThreadStart ChildRef = new ThreadStart(Child); Console.WriteLine("Main - Creating Child thread"); Thread ChildThread = new Thread(ChildRef); ChildThread.Start(); Console.WriteLine("Main - Sleeping for 2 seconds"); Thread.Sleep(2000); Console.WriteLine("\nMain - Aborting Child thread"); Console.ReadLine(); } } }

Options 1. The program will give syntactical error. The Main() function should have the following definition public static void Main() { ThreadStart ChildRef = new ThreadStart(Child); Console.WriteLine("Main - Creating Child thread"); Thread ChildThread = new Thread(ChildRef); ChildThread.Start(); 2. Console.WriteLine("Main - Sleeping for 2 seconds"); Thread.Sleep(2000); Console.WriteLine("\nMain - Aborting Child thread"); ChildThread.Abort(); Console.ReadLine(); } } The Main() function should have the following definition public static void Main() { ThreadStart ChildRef = new ThreadStart(Child); Console.WriteLine("Main - Creating Child thread"); 3. Thread ChildThread = new Thread(ChildRef); Console.WriteLine("\nMain - Aborting Child thread"); ChildThread.Abort(); Console.ReadLine(); } } The Main function should have the following definition public static void Main() { ThreadStart ChildRef = new ThreadStart(Child); Console.WriteLine("Main - Creating Child thread"); Thread ChildThread = new Thread(ChildRef); ChildThread.Start(); 4. Console.WriteLine("Main - Sleeping for 2 seconds"); Thread.Sleep(2000); Console.WriteLine("\nMain - Aborting Child thread"); Console.ReadLine(); } } }

Correct Answer: -> 2

14Question Text Which of the following statements is true? Options 1. The main() method should be declared private. The main() method can be invoked using an object of the class in which the method is 2. coded. 3. The main () method should be declared inside a class. 4. The main () method is optional when writing a Java application.

Correct Answer: -> 3

15Question Text Why do you require the public keyword in the main() method declaration? Options

1. To specify that the main() method does not return a value 2. To specify that the main() method can be accessed by all objects of the class 3. To specify that the main() method is a class method. 4. To specify the data type of the value returned by the main()

Correct Answer: -> 2

16Question Text Which of the following is the default value of Boolean type variable? Options 1. true 2. null 3. TRUE 4. false

Correct Answer: -> 4

17Question Text Which one of the following code snippets outlines the correct way to implement inheritance in Java?

Options class Fiction extends Book { void displayDetails () { 1. System.out.println(This book is out of stock); } } class Fiction extends Book, Oriental { void displayDetails () { 2. System.out.println(This book is out of stock); } } class Fiction throws Book { void displayDetails () { 3. System.out.println(This book is out of stock); } } class Fiction :: Book { void displayDetails () 4. { System.out.println(This book is out of stock); } } Correct Answer: -> 1

18Question Text

Consider the following code: class A { void dp() { System.out.println("Class A"); } } class B extends A { void dp() { System.out.println("Class B"); } } class C extends B { void dp() { System.out.println("Class C"); } } public class D extends B { void dp() { System.out.println("Class D"); } public static void main(String args[]) { D d=new D(); d.dp(); } } What will be the output? Options

1. Class D 2. Class C 3. Class B 4. Class A

Correct Answer: -> 1

19Question Text Which of the following exception will be thrown if a program tries to read from a file that does not exist?

Options 1. NullPointerException 2. SecurityException 3. FileNotFoundException 4. NumberFormatException

Correct Answer: -> 3

20Question Text

Which of the following packages contains the Frame class? Options 1. java.awt 2. java.io 3. java.net 4. javax.swing

Correct Answer: -> 4

21Question Text You are developing an application which involves the network server interaction. You have created a server and want to incorporate the code for listening to a client request. The server is into an infinite loop and listens for the client requests. Which of the following code you can incorporate in your application to accomplish the requirements? Options public Server() { try { ServerSocket = new ServerSocket(1001); } 1. catch(IOException e) { fail(e, Attempt failed.); } System.out.println(Attempt succeeds); this.start(); } 2. public void run()

{ try { while(true) { Socket client = serverSocket.accept(); Connection con = new Connection(client); } } catch(IOException e) { fail(e, Failed Attempt); } } public static void main(String args[]) { 3. new Server(); } public void run() { try { ServerSocket = new ServerSocket(1001); } 4. catch(IOException e) { fail(e, Attempt failed.); } System.out.println(Attempt succeeds); this.start(); } Correct Answer: -> 2

22Question Text Which of the following correctly defines the "runnable" state of a thread?

Options 1. if it is sleeping. 2. if it is sleeping, waiting, and is being blocked by another thread. 3. if it is sleeping and waiting. 4. When the start() mehtod of the thread is invoked.

Correct Answer: -> 4

23Question Text With reference to the start() method, which one of the following statements does not hold true? Options 1. The start() method starts a thread. 2. The thread enters the runnable state after invoking the start() method. 3. The run() method invokes the start() method. 4. The start() method allocates the system resources that are necessary for the thread.

Correct Answer: -> 3

24Question Text

Peter has designed an enrolment form for a medical college. He has used different selection controls for different fields. He has provided text boxes for names and addresses, a calendar for selecting the date of birth, and a radio button for selecting the gender. A list box is provided to select the country. However, users find it difficult to select a country because the list box does not allow the users to scroll through the options. Which control should Peter use to resolve this problem? Options 1. Radio Buttons 2. Check Boxes 3. List Boxes 4. Drop-down List Boxes

Correct Answer: -> 4

25Question Text Which of the following features of object orientation enables you to reuse the features of a generalized class? Options 1. Inheritance 2. Polymorphism 3. Abstraction 4. Encapsulation

Correct Answer: -> 1

26Question Text Which of the following features of object orientation enables an object to behave differently under different circumstances? Options 1. Encapsulation 2. Abstraction 3. Polymorphism 4. Inheritance

Correct Answer: -> 3

27Question Text Consider the following statements: Statement A: People involved in the maintenance of a system are called principal actors. Statement B: Other systems include the hardware that is a part of a system other than the computer running an application. Which of the following is correct about the statements? Options 1. Statement A is true and statement B is false. 2. Statement A is false and statement B is true. 3. Both the statements are true. 4. Both the statements are false.

Correct Answer: -> 4

28Question Text Consider the following statements: Statement A: A collaboration diagram represents a set of classes and the messages sent and received by those classes. Statement B: A sequence diagram describes the behavior of a class when accessed by external processes. Which of the following is correct about the statements? Options 1. Both the statements are false. 2. Statement A is true and statement B is false. 3. Both the statements are true. 4. Statement A is false and statement B is true.

Correct Answer: -> 2

29Question Text Consider the following code: class A { void dp() { System.out.println("Class A");

} } class B extends A { void dp() { System.out.println("Class B"); } } class C extends B { void dp() { System.out.println("Class C"); } } public class D extends B { void dp() { System.out.println("Class D"); } public static void main(String args[]) { D d=new D(); d.dp(); } } What will be the output? Options 1. Class D 2. Class C 3. Class B 4. Class A

Correct Answer: -> 1

30Question Text Consider the following statements regarding JFC: Statement A: Using JFC, you can customize components to suit your requirements. Statement B: JFC can be used to create GUI components that can then be added to your application. Which of the following is true about the given statements? Options 1. Statement A is true and statement B is false. 2. Statement A is false and statement B is true. 3. Both statements A and B are true. 4. Both statements A and B are false.

Correct Answer: -> 3

31Question Text Consider the following statements: Statement A: The setMaximumRowCount() method sets the number of elements

displayed in a drop-down list. Statement B: The isEditable() method is used to allow a user to type an entry into a combo box. Which of the following is true about the given statements? Options 1. Statement A is true and statement B is false. 2. Statement A is false and statement B is true. 3. Both statements A and B are true. 4. Both statements A and B are false.

Correct Answer: -> 1

32Question Text Consider the following code in Employee.java: import javax.swing.*; public class Employee { static JFrame frameObject; public static void main(String args[]) { frameObject = new JFrame("Employee Details"); frameObject.setSize(300,300); } } What will be the output of the above code?

Options

A frame of size 300,300 having a title bar with the content Employee Details is displayed. On clicking the close button, the window closes. A frame of size 300,300 and a title bar without any content are displayed. The frame is 2. referred to by the name Employee Details. On clicking the close button, the window closes. A frame window of size 300,300, which does not have a title bar, is displayed. The 3. frame is referred to by the name Employee Details. On clicking the close button, the window closes. 4. The frame window is not displayed. 1.

Correct Answer: -> 4

33Question Text Which one of the following keywords is used to specify a list of exceptions that a method may raise? Options 1. Extends 2. Implements 3. Throws 4. Throw

Correct Answer: -> 3

34Question Text Consider the following statements: Statement A: The Runnable interface is used to construct and access the individual threads in a multithreaded application. Statement B: You can change the priority of a thread even after the start() method is invoked. Which of the following statements is true? Options 1. Statement A is true, and statement B is false. 2. Statement A is false, and statement B is true. 3. Both statements A and B are true. 4. Both statements A and B are false.

Correct Answer: -> 2

35Question Text Presented below are a few statements in a program that is being used to display the date and the time: Thread datimeThread; Date dt; GregorianCalendar cal; String shDate, shTime, shStatus; datimeThread = new Thread(this); datimeThread.start();

Which of the following import statements are mandatory in the program? Options 1. 2. 3. 4. import java.util.Date; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.Date; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Thread;

Correct Answer: -> 1

36Question Text Which of the following correctly defines the "runnable" state of a thread? Options 1. if it is sleeping. 2. if it is sleeping, waiting, and is being blocked by another thread. 3. if it is sleeping and waiting. 4. When the start() mehtod of the thread is invoked.

Correct Answer: -> 4

37Question Text Which of the following declarations will you use to declare an array named stuObjects with four elements? Options 1. stuObjects=new Students(4); 2. stuObjects=new Students[]; 3. stuObjects=new Students[4]; 4. stuObjects=new Students();

Correct Answer: -> 3

38Question Text You are developing a software application for a bank. One of the processes involves accepting the account number of a customer and displaying the customers account details. You have created a method dispdet() in the class Custaccount. Which one of the following code snippets will you use to call the dispdet() in the Custaccount class from the main method? Options public static void main(String args[]) { 1. Custaccount.dispdet(); }

public static void main() { 2. Custaccount custobject = new Custaccount(); custobject.dispdet(); } public static void main(String args[]) { 3. Custaccount custobject = new Custaccount(); custobject.dispdet(); } public static void main(String args[]) { 4. Custaccount custobject = new custobject(); custobject.dispdet(); } Correct Answer: -> 3

39Question Text Consider the following code: class Applicant { protected String appId; protected String appName; protected String appAge; Applicant() { appId="001"; appName="Mary"; appAge="45"; } public void display() {

System.out.println(appId+" "+appName+" "+appAge+" "); } } public class Candidate extends Applicant { private String Employee; public Candidate() { Employee="Henry"; } public void displayDetails() { System.out.println(Employee); } public static void main(String args[]) { Candidate c1=new Candidate(); c1.display(); } } Which of the following statements is true about the given code? Options This code will display the following output: 001 Mary 45 This code will display the following output: 2. 001 Henry 45 This code will generate the following output: 3. Henry This code will generate the following output: 4. 001 45 1. Correct Answer: -> 1

40Question Text Which of the following samples of code creates a frame window with four buttons as shown in the exhibit? (Refer to the Graphic.) Options import javax.swing.*; import java.awt.*; public class NewFrame extends JFrame { public static void main(String args[]) { JFrame fr1; fr1 = new JFrame("My Frame"); JButton button1; JButton button2; JButton button3; JButton button4; GridLayout g1; 1. g1= new GridLayout(2,2); fr1.getContentPane().setLayout(g1); button1= new JButton("Click1"); fr1.getContentPane().add(button1); button2= new JButton("Click2"); fr1.getContentPane().add(button2); button3= new JButton("Click3"); fr1.getContentPane().add(button3); button4= new JButton("Click4"); fr1.getContentPane().add(button4); fr1.setVisible(true); fr1.setSize(500,500); } } 2. import javax.swing.*; import java.awt.*; public class NewFrame extends JFrame { public static void main(String args[]) { JFrame fr1;

fr1 = new JFrame("My Frame"); JButton button1; JButton button2; JButton button3; JButton button4; GridLayout g1; g1= new GridLayout(); fr1.getContentPane().setLayout(g1); button1= new JButton("Click1"); fr1.getContentPane().add(button1); button2= new JButton("Click2"); fr1.getContentPane().add(button2); button3= new JButton("Click3"); fr1.getContentPane().add(button3); button4= new JButton("Click4"); fr1.getContentPane().add(button4); fr1.setVisible(true); fr1.setSize(500,500); } } import javax.swing.*; import java.awt.*; public class NewFrame extends JFrame { public static void main(String args[]) { JFrame fr1; fr1 = new JFrame("My Frame"); JButton button1; JButton button2; JButton button3; JButton button4; FlowLayout f1; f1= new FlowLayout(); 3. fr1.getContentPane().setLayout(f1); button1= new JButton("Click1"); fr1.getContentPane().add(button1); button2= new JButton("Click2"); fr1.getContentPane().add(button2); button3= new JButton("Click3"); fr1.getContentPane().add(button3); button4= new JButton("Click4"); fr1.getContentPane().add(button4); fr1.setVisible(true); fr1.setSize(500,500); } }

import javax.swing.*; import java.awt.*; public class NewFrame extends JFrame { public static void main(String args[]) { JFrame fr1; fr1 = new JFrame("My Frame"); JButton button1; JButton button2; JButton button3; JButton button4; BorderLayout f1; f1= new BorderLayout(); 4. fr1.getContentPane().setLayout(f1); button1= new JButton("Click1"); fr1.getContentPane().add("North",button1); button2= new JButton("Click2"); fr1.getContentPane().add("South",button2); button3= new JButton("Click3"); fr1.getContentPane().add("East",button3); button4= new JButton("Click4"); fr1.getContentPane().add("West",button4); fr1.setVisible(true); fr1.setSize(500,500); } } Correct Answer: -> 1

S-ar putea să vă placă și