Java Certification Questions
- Which of these is the correct declaration for main?
- public static void main();
- public void static main(String []args);
- public static void main(String args);
- public static void main(String args[]);
- Which code fragments would correctly identify the number of arguments
passed via the command line to a 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?
- int count = args.length;
- int count = args.length - 1;
- int count = 0;
while (args[count] != null)
count ++;
- 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?
- 1
- -1
- 0
- What is the value of 8.7% 2.3 ?
- 1.6
- 1.8
- 1.1
- 6.4
- What will be the resulting types of the variables in the following
operations:
- a=x+y x char, y char
- a=x+y x long, y int
- a=x/y x byte, y char
- a=x%y x int, y char
- a=x&y x byte, y short
- Which of the following operations are legal in Java? x,y are both
boolean
- f(x==y);
- x=x-y;
- x=x&&y;
- x=~y;
- x^=y;
- Which of the following expressions are legal and which are not? Give your
reasons in each case.
- byte B=(byte)x; x boolean
- x=(char)(x-y); x char
- f(x&&y); x char
- x=(char)(x>>1); x char
- boolean b=(boolean) x; x char
- Which of the following expressions are legal and which are not? Give your
reasons in each case.
- x=(byte)(x % y); x byte
- x=(byte)(x>>1); x byte
- x&=y;
- boolean b=(boolean)x; x byte
- Which of the following expressions are legal and which are not? Give your
reasons in each case.
- x=x+y; x,y float
- f(x<y); x,y float
- x=x&y; x,y float
- x=x<<1; x,y float
- 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?
- if (s!=null) & (s.length()>20))
{
System.out.println(s);
}
- if (s!=null) && (s.length()>20))
{
System.out.println(s);
}
- Which of the following code fragments are legal and which are not?
Explain.
- package sportinggoods;
class Ski {
void applyWax()
{...}
}
package sportinggoods;
class DownhillSki extends Ski
{
private applyWax() {...}
}
- package Transport;
class Vehicle {
protected void Drive()
{...}
}
package Transport;
class Car extends Vehicle
{
public void Drive() {...}
}
- In same file: class Vehicle {
public void Drive()
{...}
}
class Car extends Vehicle {
private void Drive()
{...}
}
- In same file: class Ski {
private void applyWax()
{...}
}
class DownhillSki extends Ski {
void applyWax()
{...}
}
- Which of the following code fragments are legal and which are not?
Explain.
- public final class FootballGame {
void score()
{...}
}
class AmericanFootballGame extends FootballGame{
void
score() {...}
}
- public class FootballGame {
final Ball b=new
Ball("Adidas");
void test() {
b.diameter=10;
}
}
- public class FootballGame {
final Ball b=new
Ball("Adidas");
void kick() {
b=new Ball("Nike");
}
}
- public class FootballGame {
final void score()
{...}
}
class AmericanFootballGame extends FootballGame {
void
score() {...}
}
- Which of the following code fragments are legal and which are not?
Explain.
- public class SportsTournament {
abstract void finalgame()
{}
void kickoffgame() {...}
}
class WorldCup extends
SportsTournament {
void finalgame() {...}
}
- abstract class Animal {
public abstract void travel()
{}
public abstract void feed() {}
}
class Mammal extends
Animal
{
void travel() {...}
}
- interface Animal {
void travel() {}
void feed()
{}
}
class Mammal implements Animal {
void travel() {}
}
- 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.
- class FootballTeam {
int keeper=1;
static int
centerforward=9;
public static void main(String args[])
{
keeper=2;
centerforward=10;
}
- class FootballTeam {
int keeper=1;
static int
centerforward=9;
public static void main(String args[])
{
this.keeper=2;
centerforward=10;
}
- import java.awt.*;
public class Screen extends Frame
{
Screen() {
setSize(400,300);
}
public static void main(String
args[]) {
Screen theScreen=new
Screen();
theScreen.setVisible(true);
}
}
- class Rodent {
static void scavenge() {...}
}
class Rat
extends Rodent {
void scavenge() {...}
}
- class Store {
void countItems() {...}
static void main(String
args[]) {
countItems();
}
- Which of the following code fragments are legal and which are not?
Explain.
- float f=1.0;
int i=1;
byte b=i+f;
- int i=5;
long l=7;
float f=i*l;
- int i=5;
void calculate(float f) {...}
calculate(i);
- byte b;
char c;
c='k';
b=c;
- int i=1;
boolean negate(boolean b) {...}
negate(i);
- Which of the following code fragments are legal and which are not?
Explain.
- double d;
short s;
d=1.456;
s=d;
- double d=1.78;
float exponentiate(float f)
{...}
exponentiate(d);
- boolean B=true;
int i=1;
B=i;
- char c='6';
int i=9;
int add(int x,int y);
add(c,i);
- 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);
- b=517;i=233
- b=517;i=0
- b=5;i=0
- b=5;i=233
- Which of the following code fragments are legal and which are not?
Explain.
- class Fruit {
public Fruit() {...}
}
public class Orange
extends Fruit {
public Orange() {...}
public static void main(String
[]args){
Fruit f=new Fruit();
Orange o=f;
}
}
- class Fruit {
public Fruit() {...}
}
public class Orange
extends Fruit {
public Orange() {...}
public static void main(String
[]args){
Orange o=new Orange();
Fruit f=o;
}
}
- interface Fruit {
public Fruit();
}
public class Apple
implements Fruit {
public Apple() {...}
public static void main(String
[]args){
Fruit f=new Fruit();
Apple a=f;
}
}
- interface Fruit {
public Fruit();
}
public class Apple
implements Fruit {
public Apple() {...}
public static void main(String
[]args){
Apple a=new Apple();
Fruit f=a;
}
}
- interface Fruit {
public Fruit();
}
class Apple implements
Fruit {
public Apple() {...}
}
class Orange implements Fruit
{
public Orange() {...}
}
public class MyFruit {
public static
void main(String []args){
Orange o=new Orange();
Fruit f=o;
Apple
a=f;
}
}
- Which of the following code fragments are legal and which are not?
Explain.
- int i;
for (i=5,int j=10; i<10;j--) { }
- int i,j;
for (i=0,j=10;i<10, j>0;i++,j--) { }
- int i,k;
for (i=0,k=9;(i<10 &&
k>0);i++,j--) { }
- 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) {
case 1:
System.out.println("Got a 1");
break;
case 2:
case
3:
System.out.println("Got a 2 or 3");
break;
default:
System.out.println("Got somthing other than 1,2, or
3");
break;
}
- long y;
...
switch(y) {
case 1:
System.out.println("Got a 1");
break;
case 2:
case
3:
System.out.println("Got a 2 or 3");
break;
default:
System.out.println("Got somthing other than 1,2, or
3");
break;
}
- byte x;
...
switch(x) {
case 1:
System.out.println("Got a 1");
break;
case 2:
case
3:
System.out.println("Got a 2 or 3");
break;
default:
System.out.println("Got somthing other than 1,2, or
3");
break;
}
- int x=1;
int y=2;
int z=3;
int c;
...
switch(c)
{
case x:
System.out.println("Got a 1");
break;
case y:
case
z:
System.out.println("Got a 2 or 3");
break;
default:
System.out.println("Got somthing other than 1,2, or
3");
break;
}
- short x;
...
switch(x) {
case 3/3:
System.out.println("Got a 1");
break;
case 2:
case
2+1:
System.out.println("Got a 2 or 3");
break;
default:
System.out.println("Got somthing other than 1,2, or
3");
break;
}
- Which of the following code fragments are legal and which are not?
Explain.
- public static void g()
try {
f();
}catch(Exception e)
{
System.out.println("Caught in g()");
throw new Exception("thrown
from g()");
}
- public static void g()
try {
f();
}catch(Exception e)
{
System.out.println("Caught in g()");
throw new
NullPointerException("thrown from g()");
}
- public static void g() throws Throwable{
try
{
f();
}catch(Exception e) {
System.out.println("Inside
g()");
throw e.fillInStackTrace();
}
public static void main(String
[]args) {
try {
g();
} catch(Exception e)
{
System.out.println("Caught in
main");
e.printStackTrace();
}
}
- What is the output for this code fragment?
public class Rethrow
{
public static void g() throws Exception
{
System.out.println("Originates from g()");
throw new Exception("thrown
from g()");
}
public static void main(String []args) {
try
{
g();
}catch(Exception e) {
System.out.println("Caught in
main");
e.printStackTrace();
throw new NullPointerException("from
main");
}
}
- 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 draw() throws ZeroSizeException {..}
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 {
void fly();
}
class Bat
extends Mammal implements CanFly {
Bat() throws ColdBloodedException,
NoWingsException {}
void GiveBirth() {...}
}
- class Mammal {
Mammal() throws ColdBloodedException{}
void
GiveBirth() {}
}
interface CanFly {
void fly();
}
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
{
void fly();
}
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 {
public Shape ();
void
draw();
}
class Circle extends Shape {
public Circle() {
...}
void draw(double x,double y, double radius) {...}
}
- abstract class Shape {
public Shape ();
void
draw();
}
class Circle extends Shape {
public Circle() {
...}
void draw() {...}
}
- abstract class Mammal {
public Mammal();
Mammal
giveBirth();
}
class Dog extends Mammal {
public Dog ()
{...}
Dog giveBirth() {...}
}
- abstract class Mammal {
public Mammal();
Mammal
giveBirth();
}
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 {
MusicWork(String s)
{
System.out.println("The name of this work is" + s);
}
class
ClassicalWork extends MusicWork {
ClassicWork(String s, String composer)
{
System.out.println("The composer is " + composer);
}
- class MusicWork {
MusicWork(String s)
{
System.out.println("The name of this work is" + s);
}
class
ClassicalWork extends MusicWork {
ClassicWork(String s, String composer)
{
super(s);
System.out.println("The composer is " +
composer);
}
- class MusicWork {
MusicWork(String s)
{
System.out.println("The name of this work is" + s);
}
class
ClassicalWork extends MusicWork {
ClassicWork(String s, String composer)
{
System.out.println("This is a work of classical
music");
System.out.println("The composer is " +
composer);
super(s);
}
- class MusicWork {
MusicWork() {
System.out.println("This is a
work of music");
}
MusicWork(String name)
{
this();
System.out.println("The name of this work is" +
name);
}
- class MusicWork {
MusicWork() {
System.out.println("This is a
work of music");
}
MusicWork(String name)
{
this();
System.out.println("The name of this work is" +
name);
}
MusicWork(String composer)
{
this();
System.out.println("The composer of this work is" +
composer);
}
- class MusicWork {
MusicWork() {
System.out.println("This is a
work of music");
}
MusicWork(String name) {
System.out.println("The
name of this work is" + name);
this();
}
- 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 {
String a;
public class Inner {
String
b;
public void InnerMethod() {
System.out.println("Enclosing a is " +
a);
System.out.println("y i s " + y);
}
}
public void
CreateInner() {
Inner i=new Inner();
i.InnerMethod();
}
}
- public class Outer {
String a;
public class Inner {
String
b;
public void InnerMethod() {
System.out.println("Enclosing a is " +
a);
System.out.println("b is " + b);
}
}
public void
CreateInner() {
Outer.Inner i=new
Outer.Inner();
i.InnerMethod();
}
}
- public class Outer {
String a;
int k=1;
public static class
Inner {
String b;
public void InnerMethod() {
System.out.println("Enclosing a is " + a);
System.out.println("b i s
" + b);
}
}
public void CreateInner() {
Outer.Inner i=new
Outer.Inner();
i.innerMethod();
System.out.println("This is the value
of k: " + k);
}
}
- public class Outer {
static String a;
static int k;
public
Outer {
k++;
}
public class Inner {
String b;
public void
InnerMethod() {
System.out.println("Enclosing a is " + a);
System.out.println("b is " + b);
}
public void
CreateInner() {
Outer.Inner i=new
Outer.Inner();
i.InnerMethod();
System.out.println("This is the
instance no: " + k);
}
}
}
- 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) {
int
p=w-z;
final int q=w+z;
}
class Inner {
public void method
{
- System.out.println("w=" +w);
- System.out.println("z=" +z);
- System.out.println("p=" +p);
- System.out.println("q=" +q);
}
}
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 void run() {
...
wait();
...
}
}
- public class SomeStuff {
public void run() {
...
suspend();
...
}
}
- public class SomeStuff {
public void run() {
...
Thread.suspend();
...
}
}
- public void DoStuff {
public void run() {
...
Thread.yield();
}
}
- public class NewThread extends Thread {
public void run() {
...
sleep(100);
...
}
}
- Which of the following code fragments are legal and which are not?
Explain.
- public void doMath {
double pi=3.1415926;
Math mObj=new
Math();
mobj.sin(pi);
}
- public void getMax {
java.Math.max(2,2.1);
}
- public void getTan {
double
pi=3.1415926;
java.Math.tan(pi);
}
- 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)){
System.out.println("Success");
} else
{
System.out.println("Failure");
}
- String s1="Compare me";
String s2="Compare me";
if
(s1==s2){
System.out.println("Success");
} else
{
System.out.println("Failure");
}
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)){
System.out.println("Success");
} else
{
System.out.println("Failure");
- String s1=new String("Compare me");
String s2=new
String("Compare me");
if
(s1==s2){
System.out.println("Success");
} else
{
System.out.println("Failure");
}
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 try{...}catch 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:
- [ ] if ((s != null) & (s.length)>0));
- [ ] if ((s != null) && (s.length)>0));
- [ ] if ((s != null) | (s.length)>0));
- [ ] 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{
void draw();
...
}
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 static Shape
randShape() {
switch((int) (Math.random()*3)) {
default:
case 0: return
new Circle();
case 1: return new Square();
case 2: return new
Triangle();
public static void main(String[] args)
Shape[] s=new
Shape[5];
for (int i=0;i<5;i++)
Questions for the Discussion Group
- Inner Classes: I am trying to figure out the distinction between having a
static inner class and having an inner class that has static methods. I know
that for a static inner class, its methods can be called without any reference
to an enclosing class handle. But is it possible to have a non-static inner
class that has a static method defined? If so, what does this mean? That there
is no need for an inner class object?
- Constructors: Suppose I define a base class with 2 constructors, one a
default constructor with no arguments and one with an argument list as in:
class BaseClass {
public BaseClass ()
{
System.out.println("Default constructor");
}
public
BaseClass(String s) {
System.out.println("Non-default
constructor");
System.out.println(s);
}
}
Then I define a
subclass of the above class:
public Subclass extends BaseClass
{
public Subclass(String s) {
...
}
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?