Download LIST 4

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
LIST 4
Make an illustration in Eclipse the following questions:
Question 1)
Kristy works as a Software Developer for PatTech Inc. She develops an application using
Java. She writes the following code in the application:
class pClass1{
pClass1(){
System.out.println("pClass1");
}
}
public class pClass2 extends pClass1{
public static void main(String args[]){
pClass2 cc=new pClass2();
super();
}
pClass2(){
System.out.println("pClass2");
}
}
What will happen when she tries to compile and execute the application?
A. A compile time error will occur.
B. The application will compile successfully and "pClass2" followed by "pClass1" will be
displayed as output .
C. The application will compile successfully and "pClass1" followed by "pClass2" will be
displayed as output.
D. The application will compile successfully but a runtime error will occur when the
application is executed.
Question 2)
Mark works as a Software Developer for McRobert Inc. He develops an application using
Java. He writes the following code in the application:
Double d1=new Double(Double.NaN);
Double d2=new Double(Double.NaN);
if(Double.NaN==Double.NaN)
System.out.println("TRUE");
else
System.out.println("FALSE");
if(d1.equals(d2))
System.out.println("TRUE");
else
System.out.println("FALSE");
What will be displayed as output when he executes the application?
A. TRUE
TRUE
B. TRUE
FALSE
C. FALSE
TRUE
D. FALSE
FALSE
Question 3)
Which of the following statements is true?
A. Calling System.gc() results in garbage collection, but the time for the process to
complete is unspecified.
B. Calling Runtime.gc() results in garbage collection, but the time for the process to
complete is unspecified.
C. Memory leaks are impossible in Java.
D.Memory corruption due to double use of memory is impossible in Java.
Question 4)
Martin creates an application using Java language. He writes the following code snippet in
the application:
class mBasic1{
static int abc=88;
}
public class mBasic2 extends mBasic1{
public static void main(String args[]){
mBasic2 mb=new mBasic2();
mb.mMethod1();
}
public void mMethod1(){
//Statement
}
}
Which of the following statements, if placed after the comment (//) Statement, will compile
and modify the value of variable abc?
Each correct answer represents a complete solution. Choose all that apply.
A. super.abc=12;
B. abc=13;
C. mBasic1.abc=14;
D. abc=15.5
Question 5)
Peter creates an application using Java language. He implements the encapsulation feature
in the application. Which of the following options are considered as advantages of
encapsulation?
A. Encapsulation needs public methods only.
B. Encapsulation does not require any method to throw an exception.
C. Making the class final, using encapsulation, does not cause any changes to the rest of
the code.
D. Encapsulation changes the implementation and causes no consequential changes to
the rest of the code.
E. Encapsulation changes the implementation and causes consequential changes to the
rest of the code.
Question 6)
Choose the appropriate default layout managers to the containers: Panel, Frame, Applet.
Question 7)
James works as a Software Developer for JenTech Inc. He develops an application using
Java. He writes the following code in the application:
public class jClass{
public static void main(String argv[]){
jMethod(argv);
}
public void jMethod(String[] argv){
System.out.println(argv);
System.out.println(argv[1]);
}
}
What will happen when he tries to compile and execute the application?
A. A compile time error will occur stating, "Cannot make static reference to method void
jMethod(java.lang.String[]) in class jClass."
B. A compile time error will occur stating, "The main() method is not defined correctly."
C. The application will compile successfully but a runtime error will occur on execution.
D. A compile time error will occur stating, "The jMethod must be declared with a String
parameter, not a String array."
Question 8)
Alisha works as a Software Developer for AshTech Inc. She develops an application using
Java. She writes the following code in the application:
public class ASClass{
public static void main(String argv[]){
ASClass asc=new ASClass();
asc.callOn();
}
public void callOn(){
ASThread ast=new ASThread("One");
ast.start();
}
}
class ASThread extends Thread{
private String str= " ";
ASThread(String st){
str=st;
}
public void run(){
AnoWait();
System.out.println("Completed");
}
public void AnoWait(){
while(true){
try{
System.out.println("Waiting");
wait();
}
catch(InterruptedException exc){}
System.out.println(str);
notifyAll();
}
}
}
What will happen when she tries to compile and execute the application?
A. A compile time error will occur.
B. The application will compile successfully and "Waiting" will be displayed as output.
C. The application will compile successfully and "Waiting" followed by "Completed" will be
displayed as output.
D. The application will compile successfully but an exception will be thrown at runtime.
Question 9)
Vivian works as a Software Developer for VenTech Inc. He develops an application using Java.
He writes the following code in the application:
loop1: for(int k=0; k<2; k++){
for(int j=0; j<3; j++){
if(k==j){
continue loop1;
}
System.out.println("k = " + k + "j = " + j);
}
}
Which of the following will be displayed as output when he tries to compile and execute the
application?
A. k = 0 j = 1
B. k = 1 j = 0
C. k = 1 j = 2
D. k = 0 j = 0
E. k = 0 j = 2
F. k = 1 j = 1
Question 10)
Chris works as a Software Developer for BlueWell Inc. He creates an application using Java.
He writes the following code snippet in the application:
import java.awt.event.*;
import java.awt.*;
public class cFrame extends Frame implements WindowListener{
public static void main(String args[]){
cFrame cf=new cFrame();
}
public void windowClosing(WindowEvent we){
System.exit(0);
}
public void cFrame(){
setSize(200,200);
setVisible(true);
}
}
What will happen if he attempts to compile and execute the code snippet?
A. A visible frame that can be closed using the close button will be created.
B. The code snippet will give a compile time error.
C. The code snippet will compile successfully but no output will be displayed when
executed.
D. A visible frame that cannot be closed using the close button will be created.
Question 11)
Peter works as a Software Developer for SoluTech Inc. He writes the following code in a
Java application:
public class Pclass{
public static void main(String argv[]){
public static native void Pmethod();
}
}
What will happen when he tries to compile and execute the code?
A. A compile time error will occur stating, "Native methods cannot be static."
B. A compile time error will occur stating, "Native methods must return a value."
C. The code will compile successfully but an error will occur at runtime.
D. The code will compile and execute successfully.
Question 12)
James works as a Software Developer for JanTech Inc. He creates an application using Java.
He writes the following code in the application:
private class Basic{}
public class Advan{
transient int aval;
public static void main(String args[]){
}
}
What will happen when he tries to compile and execute the application?
A. A compile time error will occur stating that Basic cannot be private.
B. A compile time error will occur stating that an integer cannot be transient.
C. A compile time error will occur stating that transient is not a valid datatype.
D. A compile time error will occur stating that the main method should be defined in the
Basic class.
Question 13)
Maria works as a Software Developer for McRoberts Inc. She develops an application using
Java. She writes the following code in the application:
int k=34567;
int j= ~k;
System.out.println(j);
What will happen when she tries to compile and execute the application?
A. A compile time error will occur stating, "~ operator is applicable to Boolean values only".
B. The application will compile successfully and 34566 will be displayed as output.
C. The application will compile successfully and -34566 will be displayed as output.
D. The application will compile successfully and -34568 will be displayed as output.
E. The application will compile successfully and 34567 will be displayed as output.
Question 14)
Which of the following statements is true?
A. The finalize() method can be invoked multiple times by the garbage collector.
B. If the finalize() method is invoked, the object is garbage collected.
C. The finalize() method of an object is invoked whenever it is garbage collected.
D. The finalize() method makes an object unreachable.
Question 15)
Maria works as a Software Developer for MaryLync Inc. She develops an application using
Java. She writes the following code in the application:
String st=new String("Hello World");
int mBeg=1;
char mEnd=3;
System.out.println(st.substring(mBeg,mEnd));
What will happen when she tries to compile and execute the application?
A. A compile time error will occur stating, "No method matching substring(int, char) exists."
B. The application will compile successfully and "el" will be displayed as output.
C. The application will compile successfully and "Hel" will be displayed as output.
D. The application will compile successfully and "ell" will be displayed as output.
Question 16)
Maria creates an application using Java language. The application contains certain classes.
The class design requires that a particular member variable must be directly accessible to
any subclass of this class, and not to classes in different packages. What should Maria do to
achieve this?
A. She should mark the variable as public.
B. She should mark the variable as private.
C. She should mark the variable as protected.
D. She should not specify any special access modifier for the variable.
Question 17)
Which of the following can be used to declare an abstract method in an abstract class?
A. public abstract methodA()
B. public abstract void methodA()
C. public void abstract methodA()
D. public void methodA() {abstract;}
Question 18)
Mark works as a Software Developer for SoftTech Inc. He develops an application using Java.
He writes the following class definition in the application:
public class mClass extends mBase{
public mClass(int k){}
public mClass(int j, int k){
super(j, k);
}
}
Which of the following forms of constructor must exist explicitly in the definition of the mBase
class?
Each correct answer represents a complete solution. Choose all that apply.
A. mBase(){}
B. mBase(int j){}
C. mBase(int j, int k){}
D. mBase(int j, int k, int p){}
Question 19)
Vivian works as a Software Developer for BlueWell Inc. He develops an application using
Java. He defines a monitor, named jMon, which has ten threads in its waiting pool. All
threads have the same priority. He wants to notify one of the threads, named jThr, so that
only jThr moves from the waiting state to the ready state. How will he accomplish this?
A. Execute notify(jThr); statement from the synchronized code of jMon.
B. Execute jMon.notify(jThr); statement from the synchronized code of any thread.
C. Execute jThr.notify(); statement from the synchronized code of any thread.
D. Execute jThr.notify(); statement from the code of any thread.
E. He cannot specify the thread to be notified.
Question 20)
Martha works as a Software Developer for SamTech Inc. The Accounts department of the
company has the following job titles: Accounts Manager, Accounts Officer, and Accountant.
The company wants to store information about job title, employee ID, salary, and
department. Martha has to create a set of classes to represent it. How will she best
represent this information in Java?
A. Create different classes for Accounts Officer, Accounts Manager, and Accountant.
B. Create an Employee class and derive subclasses for Accounts Officer, Accounts Manager,
and Accountant.
C. Create an Employee class with fields for job title, employee ID, salary, and
department.
D. Create different classes for job title, employee ID, salary, and department. Create a
container class to represent employees.
Question 21)
Martha works as a Software Developer for BlueWell Inc. She develops an application using
Java. She writes the following method in the application:
/* Write method declaration here*/
{
if (method1()){
method2();
}
else{
method3();
}
}
method2 might throw an AWTException. Which of the following declarations will she use to
declare the method?
Each correct answer represents a complete solution. Choose all that apply.
A. public AWTException methodName()
B. public void methodName()
C. public void methodName() throw AWTException
D. public void methodName() throws AWTException
E. public void methodName() throws Exception
Question 22)
Which of the following codes are valid?
Each correct answer represents a complete solution. Choose all that apply.
A. String st= "Hello World";
int j=8;
st+=j;
B. String st= "Hello World";
int j=8;
if(st==j){}
C. String st= "Hello World";
int j=8;
st=st+j;
D. String st= "Hello World";
int j=8;
j=j+st;
E. String st= null;
int j=(st !=null) && (st.length()>0) ? st.length():0;
Question 23)
Which of the following methods does the Runnable interface describe?
A. run()
B. start()
C. yield()
D. stop()
Question 24)
John works as a Software Developer for JanTech Inc. He develops an application using Java.
He writes the following code in the application:
import java.io.*;
class jhBaseClass{
abstract public void display(){
}
}
public class jhMainClass{
public static void main(String argv[]){
DataInputStream dis = new DataInputStream(System.in);
try{
dis.readChar();
}
catch(IOException ioe){
System.exit(0);
}
finally {
System.out.println("Finally");
}
}
}
What will happen when he tries to compile and execute the application?
A. A compile time error will occur.
B. The application will compile successfully. On execution, it will wait for users to press any
key and then exit.
C. The application will compile successfully. On execution, it will wait for users to press any
key, display Finally as output, and then exit.
D. The application will compile successfully. On execution, it will exit immediately.
Question 25)
Which of the following statements are true about a thread being blocked using the wait()
method?
A. The thread holds an object lock.
B. The thread does not hold an object lock.
C. The thread may hold an object lock.
D. The notify() method cannot be used to invoke the thread.
Question 26)
Ross works as a Software Developer for RollTech Inc. He writes the following code in a Java
application:
class RossClass{
String str=new String("Hello");
public void Rmethod(final int rr){
int rInt;
class RBClass{
public void Rsay(){
// Write the statement here
}
}
}
public void Rother()
{
int RIntOther;
}
}
Which of the following statements can he write after the comment // Write the statement
here?
Each correct answer represents a complete solution. Choose all that apply.
A. System.out.println(str);
B. System.out.println(RIntOther);
C. System.out.println(rInt);
D. System.out.println(rr);
Question 27)
Alisha works as a Software Developer for AlTech Inc. She develops an application using
Java. She writes the following code in the application:
byte b1=113;
byte b2=126;
byte b3=b1+b2;
What will happen when she compiles and executes the code?
A. A compile time error will occur.
B. The code will compile successfully and the output will be displayed as 239.
C. The code will compile successfully and the output will be displayed as 113.
D. The code will compile successfully and the output will be displayed as 126.
Question 28)
You work as a Software Developer for JenTech Inc. You develop an application using Java. You
create two exception classes, named ExcepA and ExcepB, extending the IOException class. You
also create a method that has the following signature:
void methodA() throws IOException
Which of the following signatures can be used to override methodA()?
Each correct answer represents a complete solution. Choose three.
A. void methodA() throws Exception
B. void methodA() throws ExcepA
C. void methodA() throws ExcepA,IOException
D. void methodA() throws ExcepA,ExcepB
E. void methodA() throws ExcepA,Exception
Question 29)
Which of the following options will you choose to open the image file named FirstImage.jpg?
A. Graphics.getGraphics("FirstImage.jpg");
B. Image img=Toolkit.getDefaultToolkit().getImage("FirstImage.jpg");
C. Graphics.openImage("FirstImage");
D. Image img=new Image("FirstImage");
Question 30)
Maria works as a Software Developer for McRoberts Inc. She develops an application using
Java. She writes the following code in the application:
switch(x){
case(1):
System.out.println("1");
case(2):
case(3):
System.out.println("3");
break;
default:
System.out.println("Default");
}
Which of the following values for x will print 3 as output?
Each correct answer represents a complete solution. Choose all that apply.
A. 1
B. 2
C. 3
D. 4