Documente online.
Zona de administrare documente. Fisierele tale
Am uitat parola x Creaza cont nou
 HomeExploreaza
upload
Upload




Java Certification Questions from Apollo

Java en


Java Certification Questions from Apollo


Which of these is the correct declaration for main?



A.      public static void main();

B.       public void static main(String []args);

C.       public static void main(String args);

D.      public static void main(String args[]);

Which code fragments would correctly identify the number of arguments passed via the command line to a 18218j917s Java application, excluding the name of the class that is being invoked? What is wrong with the code fragments that are incorrect and what errors do they produce?

A.      int count = args.length;

B.       int count = args.length - 1;

C.       int count = 0;
while (args[count] != null)
count ++;

D.      int count=0;
while (!(args[count].equals("")))
count ++;

Represent the value of -192 in binary format, outlining the steps.

What is the value of -7%-2?

A.      1

B.       -1

C.       0

What is the value of 8.7%

A.      1.6

B.       1.8

C.       1.1

D.      6.4

What will be the resulting types of the variables in the following operations:

A.      a=x+y x char, y char

B.       a=x+y x long, y int

C.       a=x/y x byte, y char

D.      a=x%y x int, y char

E.       a=x&y x byte, y short

Which of the following operations are legal in Java? x,y are both boolean

A.      f(x==y);

B.       x=x-y;

C.       x=x&&y;

D.      x=~y;

E.       x^=y;

Which of the following expressions are legal and which are not? Give your reasons in each case.

A.      byte B=(byte)x; x boolean

B.       x=(char)(x-y); x char

C.       f(x&&y); x char

D.      x=(char)(x>>1); x char

E.       boolean b=(boolean) x; x char

Which of the following expressions are legal and which are not? Give your reasons in each case.

A.      x=(byte)(x % y); x byte

B.       x=(byte)(x>>1); x byte

C.       x&=y;

D.      boolean b=(boolean)x; x byte

Which of the following expressions are legal and which are not? Give your reasons in each case.

A.      x=x+y; x,y float

B.       f(x<y); x,y float

C.       x=x&y; x,y float

D.      x=x<<1; x,y float

E.       byte z=(byte)x - y; x,y byte

What is the difference between the following 2 fragments of code and which couldcause a runtime exception?

A.      if (s!=null) & (s.length()>20))

B.       if (s!=null) && (s.length()>20))

Which of the following code fragments are legal and which are not? Explain.

A.      package sportinggoods;
class Ski
}

package sportinggoods;
class DownhillSki extends Ski
}

B.       package Transport;
class Vehicle
}

package Transport;
class Car extends Vehicle
}

C.       In same file: class Vehicle
}

class Car extends Vehicle
}

D.      In same file: class Ski
}

class DownhillSki extends Ski
}

Which of the following code fragments are legal and which are not? Explain.

A.      public final class FootballGame
}
class AmericanFootballGame extends FootballGame
}

B.       public class FootballGame
}

C.       public class FootballGame
}

D.      public class FootballGame
}
class AmericanFootballGame extends FootballGame
}

Which of the following code fragments are legal and which are not? Explain.

A.      public class SportsTournament
void kickoffgame()
}
class WorldCup extends SportsTournament {
void finalgame()
}

B.       abstract class Animal
public abstract void feed()
}
class Mammal extends Animal
{
void travel()
}

C.       interface Animal {
void travel()
void feed()
}
class Mammal implements Animal {
void travel()
}

D.      abstract public class Animal {
abstract void travel()
abstract void feed()
}
class Mammal extends Animal
{
void travel()
void feed()
} (2 things wrong with this !!)

Which of the following code fragments are legal and which are not? Explain.

A.      class FootballTeam

B.       class FootballTeam

C.       import java.awt.*;
public class Screen extends Frame
public static void main(String args[])
}

D.      class Rodent {
static void scavenge()
}
class Rat extends Rodent {
void scavenge()
}

E.       class Store {
void countItems()
static void main(String args[])

Which of the following code fragments are legal and which are not? Explain.

A.      float f=1.0;
int i=1;
byte b=i+f;

B.       int i=5;
long l=7;
float f=i*l;

C.       int i=5;
void calculate(float f)
calculate(i);

D.      byte b;
char c;
c='k';
b=c;

E.       int i=1;
boolean negate(boolean b)
negate(i);

Which of the following code fragments are legal and which are not? Explain.

A.      double d;
short s;
d=1.456;
s=d;

B.       double d=1.78;
float exponentiate(float f)
exponentiate(d);

C.       boolean B=true;
int i=1;
B=i;

D.      char c='6';
int i=9;
int add(int x,int y);
add(c,i);

E.       boolean b=false;
int i=0;
b=(boolean)i;

What will be the result of the following code fragment:
short s=517;
byte b=(byte)s;
long l=233;
int i=(int) l;
System.out.println("b=" + b + ";i=" + i);

A.      b=517;i=233

B.       b=517;i=0

C.       b=5;i=0

D.      b=5;i=233

Which of the following code fragments are legal and which are not? Explain.

A.      class Fruit {
public Fruit()
}
public class Orange extends Fruit {
public Orange()
public static void main(String []args)
}

B.       class Fruit {
public Fruit()
}
public class Orange extends Fruit {
public Orange()
public static void main(String []args)
}

C.       interface Fruit
public class Apple implements Fruit {
public Apple()
public static void main(String []args)
}

D.      interface Fruit
public class Apple implements Fruit {
public Apple()
public static void main(String []args)
}

E.       interface Fruit
class Apple implements Fruit {
public Apple()
}
class Orange implements Fruit {
public Orange()
}
public class MyFruit
}

Which of the following code fragments are legal and which are not? Explain.

A.      int i;
for (i=5,int j=10; i<10;j--)

B.       int i,j;
for (i=0,j=10;i<10, j>0;i++,j--)

C.       int i,k;
for (i=0,k=9;(i<10 && k>0);i++,j--)

D.      int i,j;
for (i=0;j=10;i<10;i++,j--)

Which of the following code fragments are legal and which are not? Explain.

float x;
...
switch(x)

long y;
...
switch(y)

byte x;
...
switch(x)

int x=1;
int y=2;
int z=3;
int c;
...
switch(c)

short x;
...
switch(x)

Which of the following code fragments are legal and which are not? Explain.

public static void g()
try catch(Exception e)

public static void g()
try catch(Exception e)

public static void g() throws Throwable{
try catch(Exception e)
public static void main(String []args) catch(Exception e)
}

What is the output for this code fragment?
public class Rethrow
public static void main(String []args) catch(Exception e)

Originates from g()
Caught in main
java.lang.Exception: thrown from g()
at Rethrow.g(Rethrow.java:5)
at Rethrow.main(Rethrow.java:10)

Caught in main
java.lang.Exception: thrown from g()
at Rethrow.g(Rethrow.java:5)
at Rethrow.main(Rethrow.java:10)

Originates from g()
Caught in main
java.lang.Exception: thrown from g()
at Rethrow.g(Rethrow.java:5)
at Rethrow.main(Rethrow.java:10)
java.lang.NullPointerException: from main
at Rethrow.main(Rethrow.java: 15)

Originates from g()
Caught in main
thrown from g()
at Rethrow.g(Rethrow.java:5)
at Rethrow.main(Rethrow.java:10)
from main
at Rethrow.main(Rethrow.java: 15)

Which of the following code fragments are legal and which are not? Explain.

abstract class Shape {
Shape() throws ZeroSizeException
abstract void draw() throws ZeroSizeException;
}
class Circle
void getCircumference() throws ZeroSizeException, NegativeRadiusException

abstract class Shape {
Shape() throws ZeroSizeException
abstract void draw() throws ZeroSizeException;
}
class Circle {
void draw()
void getCircumference() throws ZeroSizeException, NegativeRadiusException
}

abstract class Shape {
Shape() throws ZeroSizeException
abstract void draw() throws ZeroSizeException;
}
class Circle {
void draw() throws ZeroSizeException, NegativeRadiusException
}

class Mammal {
Mammal() throws ColdBloodedException
void GiveBirth()
}
interface CanFly
class Bat extends Mammal implements CanFly {
Bat() throws ColdBloodedException, NoWingsException
void GiveBirth()
}

class Mammal {
Mammal() throws ColdBloodedException
void GiveBirth()
}
interface CanFly
class Bat extends Mammal implements CanFly {
Bat() throws NoWingsException
void GiveBirth()
void fly()
}

class ColdBloodedException extends Exception
class LaysEggsException extends Exception

class Mammal {
Mammal() throws ColdBloodedException, LaysEggsException
void GiveBirth()
}
class VariableBodyTemperature extends ColdBloodedException
interface CanFly
class Bat extends Mammal implements CanFly {
Bat() throws VariableBodyTemperature, NoWingsException
void GiveBirth()
void fly()
}

Which of the following code fragments are legal and which are not? Explain.
public class BaseClass {
BaseClass()
public void method() throws IOException
}

public class CaseOne extends BaseClass {
CaseOne()
public void method() throws IOException
}

public class CaseTwo extends BaseClass {
CaseTwo()
public void method()
}

public class CaseThree extends BaseClass {
CaseThree()
public void method() throws EOFException,MalformedURLException
}

public class CaseFour extends BaseClass {
CaseFour()
public void method() throws IOException, IllegalAccessException
}

public class CaseFive extends BaseClass {
CaseFive()
public void method() throws Exception
}

Which of the following code fragments are legal and which are not? Explain.

public class StockServer {
public StockServer(String company, int Shares,double currentPrice, double cashOnHand)
public double buy(int numberOfShares, double pricePerShare)
public float buy(int numberOfShares, double pricePerShare)
}

public class StockServer {
public StockServer(String company, int Shares,double currentPrice, double cashOnHand)
public double buy(int numberOfShares, double pricePerShare)
public float buy(long numberOfShares, double pricePerShare)
}

public class StockServer {
public StockServer(String company, int Shares,double currentPrice, double cashOnHand)
public double buy(int numberOfShares, double pricePerShare)
public double buy(int numberOfShares, float pricePerShare)
}

public class StockServer {
public StockServer(String company, int Shares,double currentPrice, double cashOnHand)
public double buy(int numberOfShares, double pricePerShare)
public double buy(double pricePerShare, int numberOfShares)
}

For each of the following code fragments, pleae indicate which has an overriden vs. overloaded method and explain why.

abstract class Shape
class Circle extends Shape
void draw(double x,double y, double radius)
}

abstract class Shape
class Circle extends Shape
void draw()
}

abstract class Mammal
class Dog extends Mammal {
public Dog ()
Dog giveBirth()
}

abstract class Mammal
class Dog extends Mammal {
public Dog ()
Dog giveBirth(int no_of_pups)
}

Which of the following code fragments are legal and which are not? Explain.

class MusicWork
class ClassicalWork extends MusicWork

class MusicWork
class ClassicalWork extends MusicWork

class MusicWork
class ClassicalWork extends MusicWork

class MusicWork
MusicWork(String name)


class MusicWork
MusicWork(String name)
MusicWork(String composer)

class MusicWork
MusicWork(String name)

If you create a non-default derived constructor and don't call the base class constructor will the compiler call the default base class constructor automatically? (Assume that the default constructor is defined for the base class). What about if it is not defined? What about the case of a default derived constructor, does the compiler call the default base class constructor (Eckel Chap 6).

Which of the following code fragments are legal and which are not? Explain.

public class Outer
}
public void CreateInner()
}

public class Outer
}
public void CreateInner()
}

public class Outer
}
public void CreateInner()
}

public class Outer
public class Inner
public void CreateInner()
}

Which of the following code fragments are legal and which are not? Explain.
public class Outer {
public static void main()
public void go(int w,final int z)
class Inner
}
Inner that=new Inner();
that.method;
}
}

Which of the following code fragments are legal and which are not? Explain.

public class NewThread extends Thread
}

public class SomeStuff
}

public class SomeStuff
}

public void DoStuff
}

public class NewThread extends Thread
}

Which of the following code fragments are legal and which are not? Explain.

public void doMath

public void getMax

public void getTan

Which of the following code fragments are legal and which are not? Explain.

Character c= new Character("x");

int primitive=1234;
Integer wrappedInt=new Integer(primitive);

int primitiveInt=123;
Float wrappedFloat=new Float(primitiveInt);

Vector v=new Vector();
for (int i=0;i<10;i++)
v[i]=i;

Long wLong=new Long("here");

Boolean wBoolean=new Boolean("junk");

Given the following code fragments, which of the following a,b,c,d are true?

String s1="Compare me";
String s2="Compare me";
if (s1.equals(s2)) else


String s1="Compare me";
String s2="Compare me";
if (s1==s2) else

a) Both I and II print Failure
b) Both I and II print Success
c) I print Success, II prints Failure
d) I prints Failure, II prints Success

Given the following code fragments, which of the following a,b,c,d are true?

String s1=new String("Compare me");
String s2=new String("Compare me");
if (s1.equals(s2)) else {
System.out.println("Failure");

String s1=new String("Compare me");
String s2=new String("Compare me");
if (s1==s2) else

a) Both I and II print Failure
b) Both I and II print Success
c) I print Success, II prints Failure
d) I prints Failure, II prints Success

List the 6(8) component methods you should know for the exam, and explain what they do.

Is a CheckBoxGroup a component? If not, what is it?

List the 4 elements that can populate a menu.

Which component is the only one allowed to contain a menu bar?

For a newly constructed frame, list the methods to be called to make it visible, in order.

List the 4 non-superclass container classes.

List the steps needed to create a menu bar containing a pull-down menu in order.

If the foreground and background color of a component is not set, what colors does it take on?

List the 11 visual components there are.

Explain how fonts are displayed in TextField and TextArea.

How do you release the non-memry resources of a frame?

Draw the inheritance diagram for Applet, Frame and Panel inheriting from Container.

What are the default Layout Managers for

Applet

Panel

Frame ?

Does calling setBounds ) have any effect on a component? Give a reason why or why not.

Define the behavior of each of the Layout maangers FlowLayout, GridLayout and BorderLayout wrt. the preferred size of a component.

Define the interface for the constructor of each of these Layout managers:

FlowLayout

GridLayout

BorderLayout

Define the strategy for adding a listener to a component and give an example.

Define the strategy for explicitly enabling events for a component and give an example.

State the circumstances under which the GUI thread spontaneously calls paint(), with no impetus from the program.

Why is there a need for the repaint(0 method and what does it do?


Topics

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

.

Exceptions

The need for an exception specification when an exception is thrown from a method, even within the confines of a trycatch block.

No need for an exception specification when the exception thrown is a RuntimeException.

Need to specify an exception specification for Throwable for any calling method in the call stack above a method that throws an exception object using fillInStackTrace()

Exceptions.
Correct form of output when System.out.println(), e.printStackTrace() is called, also if a Runtime Exception gets all the way to main without being called, printStackTrace() is called for that exception as the program exits.

Exception Restrictions

Method in derived class not in base class that throws exception.

Method in derived class choosing not to throw any exceptions, even if base class version does

Derived method in derived class/interface trying to add to exception interface from that of base class.

Constructor in derived class/interface throwing additional exceptions to that in the base class.

Constructor in derived class/interface throwing additional exceptions to that in the base class, but not declaring base-class exceptions in exception specification.

Derived Class Method that uses an exception derived from that used by the base-class version.

If you're dealing with a derived class object, which exceptions are you forced to catch? What if the derived class object is upcast to the base type?

Exceptions

Objects and Classes
The return type of an method is not sufficinet enough to guarantee overloading. The arguments must be of different type/order.

Objects and Classes.
An overloaded method must be strict. For a subclass method that overrides a method in its parent class, is it legal to return a type which is the subtype of the class that is returned by the overriden method in the parent class?

Objects and Classes
Constructors - non-default derived class constructors.

Objects and Classes
Constructors - non-default derived class constructors.

Inner classes

this reference and the construction of inner classes.

""

Accessibility of enclosing class variables from within static inner class.

""

Inner classes and the final keyword.

Formal parameter, non-final

Formal parameter, final

Local variable, non-final

Local variable, final

Threads

java.lang.Math class

java.lang wrapper classes.

...

..

Components

"

"

"

"

"

"

"

"

"

"

Layout Managers

"

"

"

"

Events

"

Painting

"

Oleg Melnikov Questions

Given the following definition:
String s = null;
Which code fragment will cause an object of type NullPointerException to be constructed:

A.      [ ] if ((s != null) & (s.length)>0));

B.       [ ] if ((s != null) && (s.length)>0));

C.       [ ] if ((s != null) | (s.length)>0));

D.      [ ] if ((s != null) || (s.length)>0));


In Heller's book, it states that for object reference casting, the new typemust be a superclass/interface of the class being converted, otherwise a runtime class cast exception will result. But consider the following code fragment:

abstract class Shape
class Circle extends Shape {
public Circle()
void draw()
}
class Square extends Shape {
public Square()
void draw()
}
class Triangle extends Shape {
public Triangle()
void draw()
}
public class MyShapes
public BaseClass(String s)
}

Then I define a subclass of the above class:
public Subclass extends BaseClass
My question is this:
Am I compelled to make the call to super(s) in the above constructor for SubClass(String s)? If not, and I do not make the call, will the compiler on its own, call the default base constructor super() for me, since I have defined it?


Document Info


Accesari: 2277
Apreciat: hand-up

Comenteaza documentul:

Nu esti inregistrat
Trebuie sa fii utilizator inregistrat pentru a putea comenta


Creaza cont nou

A fost util?

Daca documentul a fost util si crezi ca merita
sa adaugi un link catre el la tine in site


in pagina web a site-ului tau.




eCoduri.com - coduri postale, contabile, CAEN sau bancare

Politica de confidentialitate | Termenii si conditii de utilizare




Copyright © Contact (SCRIGROUP Int. 2024 )