Revision Java
Revision Java
1) __________ represents an entity in the real world that can be distinctly identified.
A) A class
B) An object
C) A method
D) A data field
10) The variables declared in a class for the use of all methods of the class are called
__________.
A) reference variables
B) objects
C) instance variables
D) None of these
12) Which of the following statements regarding static methods are correct?
i) Static methods are difficult to maintain, because you cannot change their implementation.
ii) Static methods can be called using an object reference to an object of the class in which
this method is defined.
iii) Static methods are always public, because they are defined at class-level.
iv) Static methods do not have direct access to non-static methods which are defined inside
the same class.
A) i and ii
B) ii and iv
C) iii and iv
D) i and iii
Write a program that takes as input the radius of a circle and finds the circumference and
area of thecircle.
Based on this problem statement, which of the following would most likely be chosen as the
class?
A) Circumference
B) Circle
C) Area
D) Radius
20) Which of the following are valid constructors within a class Test.
A) test() { }
B) Test() { }
C) void Test() { }
D) private final Test() { }
21) The default access specifier for the class members is _________.
A) public
B) private
C) protected
D) none of the above
The class name followed by parentheses specifies the _________ for the class.
A) destructor
B) constructor
C) variables
D) memory
36) Which of these is correct way of calling a constructor having no parameters, of superclass A
by subclass B?
A) super(void);
B) superclass.();
C) super.A();
D) super();
37) The dot (.) operator connects the following two entities _____.
A) a class member and a class object
B) a class object and a class
C) a class and a member of that class.
D) a class object and a member of that class
38) Consider
39) Consider
public class Test { }
A) 1
B) 2
C) Runtime error
D) Garbage value
1. class box {
2. int width;
3. int height;
4. int length;
5. }
6. class mainclass {
7. public static void main(String args[])
8. {
9. box obj = new box();
10. System.out.println(obj);
11. }
12. }
A) 0
B) 1
C) Runtime error
D) Garbage value
A) 10
B) 10 50
C) Won't compile because of line (2), constructor can't be private
D) Won't compile because of line (5), constructor can't be static
43) The following code contains one compilation error, find it?
1. public class Test {
2. Test() { }
3. static void Test() {
4. this(); }
5. public static void main(String[] args) {
6. Test();
7. }
8. }
1. class MyClass{
2. int i;
3. int j;
4.
5. public MyClass(int i, int j){
6. this.i = i;
7. this.j = j;
8. }
9.
10. public void call(){
11. System.out.print("One");
12. }
13. }
14.
15. public class Test{
16. public static void main(String args[]){
17. MyClass m = new MyClass();
18. m.call();
19. }
20. }
A) One
B) Compilation fails due to an error on line 17
C) Compilation fails due to an error on line 18
D) Compilations succeed but no output.
46) What is the expected output?
1. public class D {
2. int i;
3. int j;
4. public D(int i,int j){
5. this.i=i;
6. this.j=j;
7. }
8. public void printName() {
9. System.out.println("Name-D");
10. }
11. }
12. public class Test{ //line 1
13. public static void main (String[] args){ //line 2
14. D d = new D(); //line 3
15. d.printName(); // line 4
16.
17. }
18. }
A) Name-D
B) Compilation fails due to an error on lines 14
C) Compilation fails due to an error on lines 15
D) Compilation succeed but no output