Java Multiple Choice Questions & Answers on Applets Fundamentals for Freshers

1. Which of these functions is called to display the output of an applet?

a) display()
b) paint()
c) displayApplet()
d) PrintApplet()
Answer: b

Explanation: Whenever the applet requires to redraw its output, it is done by using method paint().
2. Which of these methods can be used to output a sting in an applet?

a) display()
b) print()
c) drawString()
d) transient()
Answer: c

Explanation: drawString() method is defined in Graphics class, it is used to output a string in an applet.
3. What does AWT stands for?

a) All Window Tools
b) All Writing Tools
c) Abstract Window Toolkit
d) Abstract Writing Toolkit
Answer: c

Explanation: AWT stands for Abstract Window Toolkit, it is used by applets to interact with the user.
4. Which of these methods is a part of Abstract Window Toolkit (AWT) ?

a) display()
b) paint()
c) drawString()
d) transient()
Answer: b

Explanation: paint() is an abstract method defined in AWT.
5. Which of these modifiers can be used for a variable so that it can be accessed from any thread or parts of a program?

a) transient
b) volatile
c) global
d) No modifier is needed
Answer: b

Explanation: The volatile modifier tells the compiler that the variable modified by volatile can be changed unexpectedly by other part of the program. Specially used in situations involving multithreading.
6. Which of these operators can be used to get run time information about an object?

a) getInfo
b) Info
c) instanceof
d) getinfoof
Answer: c
7. What is the Message is displayed in the applet made by this program?
  1.     import java.awt.*;
  2.     import java.applet.*;
  3.     public class myapplet extends Applet {
  4.         public void paint(Graphics g) {
  5.             g.drawString("A Simple Applet", 20, 20);    
  6.         }
  7.     }
a) A Simple Applet
b) A Simple Applet 20 20
c) Compilation Error
d) Runtime Error
Answer: a
8. What is the length of the application box made by this program?
  1.     import java.awt.*;
  2.     import java.applet.*;
  3.     public class myapplet extends Applet {
  4.         public void paint(Graphics g) {
  5.             g.drawString("A Simple Applet", 20, 20);    
  6.         }
  7.     }
a) 20
b) 50
c) 100
d) System dependent
Answer: a

Explanation: the code in pain() method – g.drawString(“A Simple Applet”,20,20); draws a applet box of length 20 and width 20.
9. What is the length of the application box made by this program?
  1.     import java.awt.*;
  2.     import java.applet.*;
  3.     public class myapplet extends Applet {
  4.         Graphic g;
  5.         g.drawString("A Simple Applet", 20, 20);    
  6.     }
a) 20
b) Default value
c) Compilation Error
d) Runtime Error
Answer: c

Explanation: To implement the method drawString we need first need to define abstract method of AWT that is paint() method. Without paint() method we can not define and use drawString or any Graphic class methods.
10. What is the output of this program?
  1.     import java.io.*;
  2.     class Chararrayinput {
  3.         public static void main(String[] args) {
  4.      String obj  = "abcdefgh";
  5.             int length = obj.length();
  6.             char c[] = new char[length];
  7.             obj.getChars(0, length, c, 0);
  8.             CharArrayReader input1 = new CharArrayReader(c);
  9.             CharArrayReader input2 = new CharArrayReader(c, 1, 4);
  10.             int i;
  11.             int j;
  12.             try {
  13.   while((i = input1.read()) == (j = input2.read())) {
  14.                     System.out.print((char)i);
  15.                 }
  16.             } 
  17.             catch (IOException e) {
  18.                 e.printStackTrace();
  19.      }
  20.  }
  21.     }
a) abc
b) abcd
c) abcde
d) None of the mentioned
Answer: d

Explanation: No output is printed. CharArrayReader object input1 contains string “abcdefgh” whereas object input2 contains string “bcde”, when while((i=input1.read())==(j=input2.read())) is executed the starting character of each object is compared since they are unequal control comes out of loop and nothing is printed on the screen.

Related

Multiple Choice Questions 8870773111241970642

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item