| Author |
objective type
|
rahul mehra
Ranch Hand
Joined: Aug 20, 2007
Posts: 33
|
|
which of the satatements are true? select only two a) all classes must define a constructor. b)a constructor can be declared private c)a constructor can return a value d)a constructor must initialize all the fields of the class e) a constructor can access the non static memebers of the class what will be the output of the program??? public class MyClass { long var; public void MyClass(long param) { var = param; } // (1) public static void main(String[] args) { MyClass a, b; a = new MyClass(); // (2) b = new MyClass(5); // (3) } }
|
Thanks
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12928
|
|
You can answer both of these questions quickly by writing a small program to try it out. Experimenting with Java code is a great way to learn how it works. The answer to the first question is B, E. The second program will not compile because class MyClass does not have a no-args constructor (which is needed at line (2)).
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
 |
|
|
subject: objective type
|
|
|