aspose file tools*
The moose likes Beginning Java and the fly likes objective type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
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
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14435
    
  23

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 8 API documentation
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: objective type