Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

objective type

 
rahul mehra
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
}
}
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15284
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic