OCJP Certification Sample Question Set-8

    0
    48
    Spread the love
    • 1
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
      1
      Share

    What does the following paint( ) method draw?
    Public void paint(Graphics g) {
    g.drawString(“question #6”,10,0);
    }
    The string “question #6”, with its top-left corner at 10,0
    A little squiggle coming down from the top of the component, a little way in from the left edge
    Ans : b.

    What does the following paint( ) method draw?
    Public void paint(Graphics g) {
    g.drawString(“question #6”,10,0);
    }
    A circle at (100, 100) with radius of 44
    A circle at (100, 44) with radius of 100
    A circle at (100, 44) with radius of 44
    The code does not compile
    Ans : d.

    8)What is relationship between the Canvas class and the Graphics class?
    Ans : A Canvas object provides access to a Graphics object via its paint( ) method.
    What are the Component subclasses that support painting.
    Ans : The Canvas, Frame, Panel and Applet classes support painting.
    What is the difference between the paint( ) and repaint( ) method?
    Ans : The paint( ) method supports painting via a Graphics object. The repaint( ) method is used
    to cause paint( ) to be invoked by the AWT painting method.
    What is the difference between the Font and FontMetrics classes?
    Ans : The FontMetrics class is used to define implementation-specific properties, such as ascent
    and descent, of a Font object.

    Which of the following are passed as an argument to the paint( ) method?
    A Canvas object
    A Graphics object
    An Image object
    A paint object
    Ans : b.

    Which of the following methods are invoked by the AWT to support paint and repaint operations?
    paint( )
    repaint( )
    draw( )
    redraw( )
    Ans : a.

    Which of the following classes have a paint( ) method?
    Canvas
    Image
    Frame
    Graphics
    Ans : a and c.

    Which of the following are methods of the Graphics class?
    drawRect( )
    drawImage( )
    drawPoint( )
    drawString( )
    Ans : a, b and d.

    Which Font attributes are available through the FontMetrics class?
    ascent
    leading
    case
    height
    Ans : a, b and d.

    Which of the following are true?
    The AWT automatically causes a window to be repainted when a portion of a window has been minimized and then maximized.
    The AWT automatically causes a window to be repainted when a portion of a window has been covered and then uncovered.
    The AWT automatically causes a window to be repainted when application data is changed.
    The AWT does not support repainting operations.
    Ans : a and b.

    Which method is used to size a graphics object to fit the current size of the window?
    Ans : getSize( ) method.

    What are the methods to be used to set foreground and background colors?
    Ans : setForeground( ) and setBackground( ) methods.

    You have created a simple Frame and overridden the paint method as follows
    public void paint(Graphics g){

    g.drawString(“Dolly”,50,10);

    }

    What will be the result when you attempt to compile and run the program?
    The string “Dolly” will be displayed at the centre of the frame
    b) An error at compilation complaining at the signature of the paint method
    c) The lower part of the word Dolly will be seen at the top of the form, with the top hidden.
    d) The string “Dolly” will be shown at the bottom of the form
    Ans : c.

    Where g is a graphics instance what will the following code draw on the screen.
    g.fillArc(45,90,50,50,90,180);
    a) An arc bounded by a box of height 45, width 90 with a centre point of 50,50, starting
    at an angle of 90 degrees traversing through 180 degrees counter clockwise.
    b) An arc bounded by a box of height 50, width 50, with a centre point of 45,90 starting
    at an angle of 90 degrees traversing through 180 degrees clockwise.
    c) An arc bounded by a box of height 50, width 50, with a top left at coordinates of 45,
    90, starting at 90 degrees and traversing through 180 degrees counter clockwise.
    d) An arc starting at 45 degrees, traversing through 90 degrees clockwise bounded by a
    box of height 50, width 50 with a centre point of 90, 180.
    Ans : c.

    Given the following code
    import java.awt.*;
    public class SetF extends Frame{
    public static void main(String argv[]){
    SetF s = new SetF();
    s.setSize(300,200);
    s.setVisible(true);
    }
    }

    How could you set the frame surface color to pink
    a)s.setBackground(Color.pink);
    b)s.setColor(PINK);
    c)s.Background(pink);
    d)s.color=Color.pink
    Ans : a.

    Don't miss out!
    Subscribe To Newsletter

    Receive top technical news, lesson ideas, travel tips and more!

    Invalid email address
    Give it a try. You can unsubscribe at any time.

    Spread the love
    • 1
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
      1
      Share

    LEAVE A REPLY

    Please enter your comment!
    Please enter your name here