aspose file tools
The moose likes Beginning Java and the fly likes objective type Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "objective type" Watch "objective type" New topic
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
    
    3

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
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: objective type
 
Similar Threads
Constructor question
Constructor
i need help
constructors and methods
Private Class????