0% found this document useful (0 votes)
2K views27 pages

Java MCQs for CS-506 Students

The document contains questions and answers related to Java programming concepts. It covers topics like inner classes, variables, exceptions, streams, interfaces, inheritance, polymorphism and more. The document is intended as a practice quiz for students.
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)
2K views27 pages

Java MCQs for CS-506 Students

The document contains questions and answers related to Java programming concepts. It covers topics like inner classes, variables, exceptions, streams, interfaces, inheritance, polymorphism and more. The document is intended as a practice quiz for students.
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/ 27

CS-506 Web Design & Develop

Update MCQS For Quiz-2 File


Solve By Vu Topper RM
80 To 100% Marks

For More Help Contact What’s app 03224021365


Which of the following is NOT true for java inner classes?
A. Can have Methods
B. Can have constructors
C. Can have instance variables
D. Generally used as public utility classes Page 121

Which of the following statement regarding Java is false?


A. Java uses an interpreter
B. Java is case sensitive language
C. Java is a programming language
D. A Java program compiles into machine language Page 8

Bytecodes are put in memory by ________________ .


A. Editor
B. Compiler
C. Class loader Page 11
D. Bytecode verifier

_________ is correct syntax to get component area of “myFrame” top


level container.
A. Container c = myFrame.getContentArea();
B. Container c = myFrame.getContentPane(); Page 92
C. Container c = myFrame.getComponentPane();
D. Container c = myFrame->getComponentArea();

____________ in a collection class creates a collection with no


elements.
A. Class
B. Array
C. Function
D. Constructor Page 45

For More Help Contact What’s app 03224021365


Which of the following is a valid variable name in Java?
A. 1xu
B. Long
C. vu.506
D. Number Of Student Google

Which one of the following blocks always executes irrespective of


exception occurrence?
A. Try block
B. Catch block
C. Switch block
D. Finally block Page 72

CmdArgs java class is compiled. If the command “java CmdArgs


CS506” run in cmd, then what will be output of given code.
Public class CmdArgs{
public static void main(String[] args)
{
System.out.println("First argument " + args[0]);
}
A. CS506
B. args[0]
C. Syntax error Google
D. do not show any output
Window, frame and dialog use ________ as their default layout.
A. Flow layout
B. Grid layout
C. Border layout Google
D. GridBag layout
The classes which contain the word _____ in their names are byte
oriented streams.
A. Byte

For More Help Contact What’s app 03224021365


B. Writer
C. Stream Page 71
D. Reader

Which one of the following methods is not a method of MouseListener


interface?
A. Moved Page 113
B. Clicked
C. Pressed
D. Released

Interface imposes _______________ structure on any class that uses


interface.
A. Code
B. Design Page 85
C. Inheritance
D. Implementation

Java core language is _______ than C++.


A. Simpler Page 5
B. Difficult
C. Complex
D. Less secure

Which of the following is the correct java code statement that is used to
establish the connection?
A. Connection con = driverManager.getConnection(conURL)
B. connection Con = driverManager.getConnection(conURL)
C. connection Con = driverManager.getConnection(conURL)
D. Connection con = DriverManager.getConnection(conURL)
Google

For More Help Contact What’s app 03224021365


Which of the following functions is declared in MouseMotionListener
interface?
A. public void mouseClicked (MouseEvent me);
B. public void mousePressed (MouseEvent me);
C. public void mouseEntered (MouseEvent me);
D. public void mouseDragged (MouseEvent me); Page 113

In java, adapter classes have been defined for the following listener
interfaces except for ________ interface.
A. ItemListener Page 119
B. FocusListener
C. ComponenetListener
D. MouseMotionListener

Which statement from the following statements is true about a java


Anonymous Inner Class?
A. It has no name
B. It is much shorter
C. All of the given options Page 127
D. It is difficult to understand

Which of the following is a top level container?


A. JPanel
B. Dialog Page 90
C. ToolBar
D. ScrollPane

Which of the following features provides the facility for multiple


inheritance?
A. Collections
B. Interfaces Page 85
C. Adapter classes
D. Wrapper classes

For More Help Contact What’s app 03224021365


Which of the following statement object is used to execute simple SQL
statement?
A. Statement Page 140
B. None of given
C. Callable Statement
D. Prepared Statement

== operator compares _________ of strings whereas equals() method


compares _________ of strings.
A. Addresses, size
B. Size, addresses
C. Values, addresses
D. Addresses, values Page 19

Which of the following name is used by the system to recognize the


underlying data source?
A. DNS
B. DSN Page 130
C. JDBC
D. ODBC

In polymorphism __________________ are overridden.


A. Classes
B. Methods
C. Variables
D. Data type Page 8

An event in java is represented as ________


A. Object Page 103
B. Function
C. Operator
D. Primitive data type

For More Help Contact What’s app 03224021365


All the exceptions and errors in java are inherited from _____ class.
A. Error
B. Exception
C. Throwable Page 55
D. IOException

ArrayList is an example of _______collection type.


A. Set based
B. Hashmap based
C. Sequence based Google
D. None of the given

DDL stands for?


A. Data Driven Language
B. Data Definition Language Page 137
C. Database Driven Language
D. Database Definition Language

While running following ExceptionExample.java class on command line


without passing command line arguments gives ____________
exception.
A. IO Exception
B. Null pointer exception
C. Divide by zero exception
D. Array index out of bound exception Page 58

Bytecodes are created and stored on disk by ___________ .


A. Editor
B. Compiler Page 11
C. Class loader
D. Bytecode verifier

For More Help Contact What’s app 03224021365


Which of the following streams is a filter stream?
A. File Writer
B. File Reader
C. Buffered Reader Page 69
D. All of given options
Which of the following package needs to import while interacting with a
relational database?
A. Java.io
B. java.sql Page 129
C. java.awt
D. javax.swing

A class that is defined in another class is called ________.


A. Inner class Page 121
B. Public class
C. Private class
D. Derived class

Which of the following statement object is used to execute using same


query multiple times by only changing parameters?
A. Statement
B. CallableStatement
C. PreparedStatement Page 140
D. Both PreparedStatement and CallableStatement

In given lines of code, __________________ is applying .


nt a = 20;
double b = a;
A. upcasting a to b type Page 43
B. upcasting b to a type
C. downcasting b to a type
D. downcasting a to b type

For More Help Contact What’s app 03224021365


Choose the correct syntax to declare an abstract java class named as
"Person".
A. abstract public class Person{}
B. public class Person abstract{}
C. public class abstract Person{}
D. public abstract class Person{} Page 83
Based on functionality, the streams can be categorized as ________
A. Node stream and Filter stream Page 83
B. Byte oriented stream and Node stream
C. Filter stream and Character oriented stream
D. Byte oriented stream and Character oriented stream

____________________ is/are not part of java core language.


A. Array
B. Objects
C. Variables
D. Array List class Page 4

Which of the following statement object is used to execute precompiled


SQL statements?
A. Statement
B. CallableStatement
C. PreparedStatement Page 140
D. Both PreparedStatement and CallableStatement

In given lines of code Employee is super class, Teacher is child class,


________________ is applying.
A. upcasting Employee to Teacher type Page 44
B. upcasting Teacher to Employee type
C. downcasting Employee to Teacher type
D. downcasting Teacher to Employee type

For More Help Contact What’s app 03224021365


All java files in a directory are compiled using
_______________command in command prompt.
A. javac all
B. java *.java
C. javac *.java Page 6
D. javac all.java

If a class implements an interface then _________


A. an interface must provide implementation of all methods
Page 85
B. a class must provide implementation of all methods of interface
C. a class may or may not provide implementation of all methods of
interface
D. class will compile successfully if class do not implements methods
of interface

Which of the following features is available in java?


A. Pointers
B. Global variables
C. Primitive data types Page 40
D. Operator overloading

A hash map object is to create, to store Teacher objects as values and


their CNIC in the form of strings as keys.Which syntax is correct for this
requirement?
A. HashMap <String> h =new HashMap<String>();
B. HashMap <Teacher> h =new HashMap<Teacher>();
C. HashMap <Teacher> h =new HashMap<String,Teacher>();
D. HashMap <String,Teacher> h =new HashMap<String,
Teacher>(); Page 279

Which of the following is true about AWT and SWING components?


A. Both AWT and SWING component creates a thread.

For More Help Contact What’s app 03224021365


B. Both AWT and SWING component creates a process.
C. AWT components creates a process whereas SWING
component creates a thread. Page 88
D. AWT components creates a thread whereas SWING component
creates a process.

Which of the given Listener Interfaces is need to handle the


“KeyEvent”?
A. KeyListener Page 105
B. KeyActionListener
C. MouseKeyListener
D. MotionKeyListener

In given lines of code _________ is static variable and __________ is


static method.System.out.println(“CS506”);
JOptionPane.showMessageDialog(null,”CS506”)
A. Println, JOptionPane
B. System, JOptionPane
C. Out, showMessageDialog Page 34
D. Println, showMessageDialog

A collection can store _________


A. At most 100 objects
B. Homogenous objects Page 61
C. Heterogeneous objects
D. Objects as well as primitive values

Mouse events can be trapped for ________ GUI component.


A. JPanel
B. JFrame
C. JButton
D. All of given Page 113

For More Help Contact What’s app 03224021365


WindowListener interface contains _______ methods.
A. Six
B. Four
C. Eight
D. Seven Page 128

A variable declared as static in a class is a/an _________


A. Class variable Google
B. Const variable
C. Global variable
D. Instance variable

In java, overloading is _______ whereas overriding is _____ .


A. Run time binding, late time binding
B. Late binding, compile time binding
C. Run time binding, compile time binding
D. Compile time binding, run time binding Google

Which of the following is a general purpose container?


A. Dialog
B. JFrame
C. JPanel Page 90
D. JApplet

The following is an example of ________.


FileReader fr = new FileReader(“input.txt”);
A. File stream
B. Node stream Page 69
C. Filter stream
D. Byte oriented stream

AWT is also called ______.


A. Light weight components

For More Help Contact What’s app 03224021365


B. Heavy weight components Page 88
C. Neither Light weight nor heavy weight
D. Both Light weight and heavy weight components

If there is no exception in the try block then the catch block ________
executes.
A. Never Google
B. Always
C. Sometime
D. None of the given

The given line of code will result in ________


System.out.println(5+9);
A. 5+9
B. 14 Page 19
C. 59
D. Syntax error

Which of the following exception belongs to a category of un-checked


exception?
A. IOException
B. AWTException
C. Null Pointer exception Page 71
D. ClassNotFoundException

HashMap takes key as a/an _________


A. Array
B. Object Page 47
C. Function
D. Primitive value

To compile all the .java files, the java compiler is called______, on


UNIX or Windows.

For More Help Contact What’s app 03224021365


A. javac Page 6
B. cjava
C. java.c
D. c java

Teacher.java class wants to inherit from Employee.java class,


___________ keyword should be used in blank space in given code to
apply inheritance. class Teacher ------------ Employee
{public static void main (String args[]){ }}
A. Inherit
B. Extends Page 39
C. Override
D. Implement

Which command of the following commands is used to compile


“JavaTest” java file’s code?
A. java JavaTest
B. javac JavaTest
C. java JavaTest.java
D. javac JavaTest.java Page 33

CREATE, ALTER, DROP are _________ SQL statements.


A. DCL
B. DML
C. DDL Page 137
D. None of given

Following are the code statements used in java event handling. Identify
the code statement that is used for handling an event
A. button = new JButton("Reset")
B. button.addActionListener(this)
C. container.setLayout(new FlowLayout());
D. public void actionPerformed(ActionEvent e) Page 106

For More Help Contact What’s app 03224021365


If there is a class "Student", then the java file must be saved with ______
name.
A. Any name
B. Student.java
C. student.java Page 30
D. Student_File.java
The relationship between class and interface is called ________
A. ‘Is a’ relationship Page 98
B. ‘Has a’ relationship
C. ‘Responds to’ relationship
D. None of the given options

Converting a bigger data type into smaller data type is called____.


A. Up-casting
B. High-casting
C. Down-casting Page 44
D. Normal-casting

Which of the following keyword/operator is used for inheritance in java?


A. Inherit
B. : (colon)
C. Extends Page 38
D. Implements

Which feature of the following features does Java provide?


A. Pointers
B. Multiple Inheritance
C. Function Overriding Page 5
D. Operator Overloading

In Editor java programs are created, while they are stored on/in
____________ .
A. Usb

For More Help Contact What’s app 03224021365


B. Disk Page 11
C. External file
D. Primary memory

____________________ returns the elements at specified position in the


list.
A. Object set(int index)
B. Object get(int index) Page 46
C. Object return(int index)
D. Object remove(int index)

JDBC-ODBC stands for ________.


A. Java DataBase Corporation- Open DataBase Corporation
B. Java DataBase Corporation- Oracle DataBase Corporation
C. Java DataBase Connectivity- Oracle DataBase Connectivity
D. Java DataBase Connectivity- Open DataBase Connectivity
Page 162

Which of the following is a correct listener statement for “mouse click”


event in “MouseListener” interface?
A. public void mouseclicked (MouseEvent me)
B. public void Mouseclicked (MouseEvent me)
C. public void mouseClicked (MouseEvent me) Page 114
D. public void MouseClicked (MouseEvent me)

The toString() method returns a _________ representation of _______


A. int, string
B. string, int
C. object, string
D. string, object Page 34

To make sure array accesses touch only the memory allocated to them ,
JVM does _______________ checking at runtime.
A. Not

For More Help Contact What’s app 03224021365


B. Static
C. Dynamic Page 5
D. Consistent

Mouse motion event is generated when mouse is:


A. Clicked
B. Entered
C. Pressed
D. Dragged Page 113

Which of the following method is used to execute INSERT, UPDATE


and Delete SQL statements?
A. executeQuery(sql);
B. ExecuteQuery(sql);
C. executeUpdate(sql); Page 134
D. ExecuteUpdate(sql);

Given code is showing the result of addition of two integer type


numbers. Choose correct output of this code.
Int i = 7;
int j = 8;
int k = i+j;System.out.println(“Seven ” + i + “ plus Eight ” + j + “ is “ +
k)
A. Seven plus Eight is k
B. Seven i plus Eight j is k
C. Seven 7 plus Eight 8 is 15 Google
D. Seven i plus Eight j is + 15

Which of the following streams is a byte oriented stream?


A. PrintWriter
B. FileReader
C. BufferedReader
D. FileInputStream Page 71

For More Help Contact What’s app 03224021365


Which of the following statement object is used to execute stored
procedures?
A. Statement
B. CallableStatement Page 140
C. PreparedStatement
D. Both PreparedStatement and CallableStatement

Which of the following is called “pure abstract class”?


A. Collections
B. Interfaces Page 85
C. Adapter classes
D. Wrapper classes

Java language has a little worse performance than C++ language,


because ______________.
A. it is object oriented
B. it uses built in libraries
C. it does not use pointers
D. it checks all errors, malicious and viruses Page 5

Which of the given Listener Interface is needed to handle the


“MouseEvent”?
A. Mouse Listener Page 105
B. KeyActionListener
C. MouseKeyListener
D. MotionKeyListener

Which of the following statements is a correct statement for “mouse


release” event in “MouseListener” interface?
A. public void mouseExited (MouseEvent me);
B. public void mouseEntered (MouseEvent me);
C. public void mouseClicked (MouseEvent me);
D. public void mouseReleased (MouseEvent me); Page 114

For More Help Contact What’s app 03224021365


Adapter classes have been defined for listener interfaces except
________ interface.
A. KeyListener
B. MouseListener
C. ActionListener Page 119
D. WindowListener

If a class needs to handle events generated by button then which of the


following interfaces a class needs to implement?
A. KeyListener
B. MouseListener
C. ActionListener Page 106
D. WindowListener

Which of the following statements attaches an output stream to console?


A. FileWriter fw = new FileWriter(FileDescriptor);
B. FileWriter fw = new FileWriter(“output.txt”); Page 80
C. FileWriter fw = new FileWriter(FileDescriptor.in);
D. FileWriter fw = new FileWriter(FileDescriptor.out);

Following are the code statements used in java event handling. Identify
the code statement that is used for generating an event
A. frame = new JFrame
B. frame.setSize(150, 150)
C. b1 = new JButton("OK") Page 105
D. b1.addActionListener(this)
The class that handles mouse event needs to implement the
corresponding interface and to provide the definition of:
A. One method in that interface
B. Two methods in that interface
C. Three methods in that interface
D. All the methods in that interface Google

For More Help Contact What’s app 03224021365


If we want to call toString() method of parent class in JAVA. Which of
the following statements will be used?
A. this. toString();
B. sub. toString();
C. new. toString();
D. super.toString(); Page 40

Java is a _____________ language.


A. Static
B. Not portable
C. Complicated
D. Multi threaded Page 4

Which of the following classes is capable to instantiate?


A. Abstract class
B. Interface class
C. Concrete class Page 83
D. None of the given

In Java, ____________ types of statement objects are available for


sending SQL queries to the databases.
One
Two
Five
Three Page 140

Which of the following classes provide definitions for all the methods
(empty bodies) of their corresponding Listener interface?
Inner classes
Public classes
Private classes
Adapter classes Page 118

For More Help Contact What’s app 03224021365


Which of the given Listener Interface is needed to handle the
“ActionEvent”?
A. KeyListener
B. MouseListener
C. ActionListener Page 106
D. WindowListener

Which of the following objects is passed as an argument to


paintComponent() method?
A. Image object
B. JPanel object
C. JFrame object
D. Graphics object Google

The “MouseDragged” and “mouseMoved” methods are defined in


________ interface.
A. ItemListener
B. MouseListener
C. ActionListener
D. MouseMotionListener Page 113

Which of the following method/s is a ResultSetMetaData method?


A. getColumnCount ()
B. getColumnName(int)
C. getColumnDisplaySize (int)
D. All of the given options Page 157

Which of the following code statement is used to define a connection


URL?
A. String asd = “jdbc:odbc:DSNname" Page 133
B. Statement xyz = abc.createStatement()
C. Class.forName(“sun.jdbc.odbc.JdbcOdbcDriver)
D. Connection abc = DriverManager.getConnection(conURL)

For More Help Contact What’s app 03224021365


In order to include graphics in your Java program, it is mandatory to
extend from _________ class.
A. JLabel
B. JPanel Page 171
C. JFrame
D. JButton

In the context of Java Graphics, paintChildren( ) method tells any


component contained by this component to paint itself.
True Page 170
False

All AWT and swing components generate events.


True Page 103
False

Which of the following methods is a correct registration method for


Focus Listener interface?
A. regFocusListener
B. addFocusListener
C. regFocusedListener
D. addFocusedListener

A database that is created in MS Access 2003 will be saved with


_________ extension.
A. . doc
B. . java
C. . mdb Page 131
D. .class

For More Help Contact What’s app 03224021365


Which of the following statements is a DDL statement?
A. Add
B. Delete
C. Create Page 137
D. Update

There are ________ steps in order to communicate successfully with


database.
A. Six
B. Nine
C. Eight Page 132
D. Seven

Java defines ________ for the listener interfaces having more than one
event handling methods.
A. Wrapper classes
B. Adapter classes
C. Abstract classes Page 118
D. Concrete classes

ResultSet provides various getters to retrieve __________.


A. column headers
B. data of the row
C. data of the column Page 134
D. data of the row and column

Let suppose a column has index 5 in the ResultSet object. Which of the
following statement is used to retrieve the column values?
A. String name = rs.getInt(5)
B. String name = rs.getInt(4)
C. String name = rs.getString(4)
D. String name = rs.getString(5) Page 134

For More Help Contact What’s app 03224021365


Which of the following methods is used to determine whether a database
is read only or not?
A. isreadonly()
B. IsReadOnly()
C. isReadonly()
D. isReadOnly() Page 167

INSERT, UPDATE, DELETE are ____________ statements.


A. DCL
B. DDL
C. DML Page 144
D. None of given

Event handling is a _______ step process.


A. One
B. Two
C. Five
D. Three Page 104

Which of the following method is used to execute SELECT SQL


statements?
A. ExecuteQuery(sql);
B. ExecuteUpdate(sql);
C. executeQuery(sql); Page 134
D. executeUpdate(sql);

Which of the following is NOT a method of ResultSet method?


A. next()
B. absolute(int)
C. updateRow()
D. executeQuery(sql) Page 150

For More Help Contact What’s app 03224021365


In the context of Java Graphics, which of the following methods we
should override while painting?
A. paint( ) Page 170
B. paintBorder( )
C. paintChildern( )
D. paintComponet( )

Which of the given methods is/are declared for “MouseListener”


interface?
A. MouseMoved
B. MousePressed Page 113
C. MouseDragged
D. MouseKeyPressed

Which of the following statements is true regarding paintChildren()


method?
A. It tells the component to paint its border.
B. It first paints the background and then performs custom painting.
C. It first performs custom painting and then paints the background.
D. It tells any components contained by this component to paint
themselves. Page 170

previous() is a method of __________ object.


A. Statement
B. ResultSet Page 145
C. Connection
D. ResultSetMetaData

Which of the following statements is true regarding paintComponent()


method?
A. It tells the component to paint its border.
B. It first performs custom painting and then paints the background.

For More Help Contact What’s app 03224021365


C. It first paints the background and then performs custom
painting. Page 170
D. It tells any components contained by this component to paint
themselves.

getColumnCount() is a method of ________ object.


A. Statement
B. ResultSet
C. DataBaseMetaData
D. ResultSetMetaData Page 157

In Java Graphics, while painting a swing component, which of the


following functions is invoked first?
A. paint( )
B. paintBorder( )
C. paintChildern( )
D. paintComponet( ) Page 169

ResultSet Meta Data will help you in answering the following questions
except:
What is the name of given column?
How many rows are in the ResultSet? Page 156
Are the column name is case sensitive?
How many columns are in the ResultSet?

The __________ method returns true or false depending upon whether


the next row is available (exist) or not in ResultSet.
A. close()
B. next() Page 144
C. close()
D. getters

For More Help Contact What’s app 03224021365


A scrollable and updatable ResultSet object has the following
capabilities except ________
A. delete rows
B. update rows
C. insert new rows
D. insert new columns Page 144

DSN stands for _________


A. Data System Name
B. Data Source Name Page 130
C. Domain system Name
D. Database System Name

If a JPanel has a triangle drawn on it then which of the following


methods will display it?
A. paint( )
B. paintBorder( )
C. paintChildern( )
D. paintComponet( ) Page 169

Which of the following method is used to release the JDBC and database
resources in ResultSet?
A. next()
B. close() Page 144
C. getters
D. previous()

In ResultSetMetaData methods, ________ method returns the SQL type


for the column to compare against types in java.sql.Types.
A. getColumnCount ( )
B. getColumnType (int) Page 157
C. getColumnName(int)
D. getColumnDisplaySize (int)

For More Help Contact What’s app 03224021365

You might also like