SCJP Quiz
  Page #6
 
Topic: Declarations and access control
Question #51

If you create a TextField with a constructor to set it to occupy 5 columns, what difference will it make if you use it with a proportional font (ie Times Roman) or a fixed pitch typewriter style font (Courier).
  1. With a fixed font you will see 5 characters, with a proportional it will depend on the width of the characters
  2. With a fixed font you will see 5 characters,with a proportional it will cause the field to expand to fit the text
  3. The columns setting does not affect the number of characters displayed
  4. Both will show exactly 5 characters
Click here to see the answer
Click here to see explanation

Question #52

Given the following code how could you invoke the Base constructor that will print out the string "base constructor";
class Base
{
    Base(int i)
    {
        System.out.println("base constructor");
    }
    Base(){}
}

public class Sup extends Base
{
    public static void main(String argv[])
    {
        Sup s= new Sup();
        //One
    }
    Sup()
    {
        //Two
    }

    public void derived()
    {
        //Three
    }
}
  1. On the line After //One put Base(10);
  2. On the line After //One put super(10);
  3. On the line After //Two put super(10);
  4. On the line After //Three put super(10);
Click here to see the answer
Click here to see explanation

Question #53

Given the following code what will be output?
public class Pass
{
    static int j=20;
    public static void main(String argv[])
    {
        int i=10;
        Pass p = new Pass();
        p.amethod(i);
        System.out.println(i);
        System.out.println(j);
    }

    public void amethod(int x)
    {
        x=x*2;
        j=j*2;
    }
}
  1. Error: amethod parameter does not match variable
  2. 20 and 40
  3. 10 and 40
  4. 10, and 20
Click here to see the answer
Click here to see explanation

Question #54

What code placed after the comment //For loop would result in the population of every element of the array ia[] with a value from variable i.?
public class Lin
{
    public static void main(String argv[])
    {
        Lin l = new Lin();
        l.amethod();
    }
    public void amethod()
    {
        int ia[] = new int[4];
        //Start For loop
        {
            ia[i]=i;
            System.out.println(ia[i]);
        }
    }
}
  1. for(int i=0; i < ia.length() -1; i++)
  2. for (int i=0; i< ia.length(); i++)
  3. for(int i=1; i < 4; i++)
  4. for(int i=0; i< ia.length;i++)
Click here to see the answer
Click here to see explanation

Question #55

What will be the result when you try to compile and run the following code?
private class Base
{
    Base()
    {
        int i = 100;
        System.out.println(i);
    }
}

public class Pri extends Base
{
    static int i = 200;
    public static void main(String argv[])
    {
        Pri p = new Pri();
        System.out.println(i);
    }
}
  1. Error at compile time
  2. 200
  3. 100 followed by 200
  4. 100
Click here to see the answer
Click here to see explanation

Question #56

What will the following code print out?
public class Oct
{
    public static void main(String argv[])
    {
        Oct o = new Oct();
        o.amethod();
    }
    public void amethod()
    {
        int oi= 012;
        System.out.println(oi);
    }
}
  1. 12
  2. 012
  3. 10
  4. 10.0
Click here to see the answer
Click here to see explanation

Question #57

What will happen when you try compiling and running this code?
public class Ref
{
    public static void main(String argv[])
    {
        Ref r = new Ref();
        r.amethod(r);
    }
    public void amethod(Ref r)
    {
        int i=99;
        multi(r);
        System.out.println(i);
    }
    public void multi(Ref r)
    {
        r.i = r.i*2;
    }
}
  1. Error at compile time
  2. An output of 99
  3. An output of 198
  4. An error at runtime
Click here to see the answer
Click here to see explanation

Question #58

You need to create a class that will store unique object elements. You do not need to sort these elements but they must be unique. What interface might be most suitable to meet this need?
  1. Set
  2. List
  3. Map
  4. Vector
Click here to see the answer
Click here to see explanation

Question #59

Which of the following will successfully create an instance of the Vector class and add an element?
  1. Vector v=new Vector(99); v[1]=99;
  2. Vector v=new Vector(); v.addElement(99);
  3. Vector v=new Vector(); v.add(99);
  4. Vector v=new Vector(100); v.addElement("99");
Click here to see the answer
Click here to see explanation

Question #60

You have created a simple Frame and overridden the paint method as follows: What will be the result when you attempt to compile and run the program?
public void paint(Graphics g)
{
    g.drawString("Dolly",50,10);
}
  1. The string "Dolly" will be displayed at the centre of the frame
  2. An error at compilation complaining at the signature of the paint method
  3. The lower part of the word Dolly will be seen at the top of the frame, with the top hidden.
  4. The string "Dolly" will be shown at the bottom of the frame.
Click here to see the answer
Click here to see explanation

 
  Today, there have been 1 visitors (2 hits) on this page!  
 
This website was created for free with Own-Free-Website.com. Would you also like to have your own website?
Sign up for free