Object-oriented programming with Java Classes and Objects

Object-oriented programming with Java Classes and Objects


1) In Java, objects will expose variables and functions in these variables are also known as?

A) Fields
B) Methods
C) Fields & Methods
D) None of the above
View Answer / Hide Answer

ANSWER: Fields




2) In which the access modifier means that the field can be accessed by all classes in your application?

A) private
B) Public
C) Package
D) Protected
View Answer / Hide Answer

ANSWER: Public




3) Static fields belong to the class, not instances of the class?

A) True
B) False
View Answer / Hide Answer

ANSWER: True




4) Which field cannot be changed after the object has been constructed?

A) Static field
B) Non-static field
C) Final field
D) Naming field
View Answer / Hide Answer

ANSWER: Final field




5) The following syntax is used to declare,
[access_modifier] [static] [final] type name [= initial value] ; ?

A) Field
B) Method
C) Overloading method
D) Both B & C
View Answer / Hide Answer

ANSWER: Field




6) Which is a non-static method having the same name as its class?

A) Field
B) Method
C) Constructor
D) None of the above
View Answer / Hide Answer

ANSWER: Constructor




7) Constructor is like a method that is used to initialize the state of an object. It is invoked at the time of object creation?

A) True
B) False
View Answer / Hide Answer

ANSWER: True




8) Which is a technique in Java in which a class can have any number of constructors that differ in parameter lists?

A) Constructor overloading
B) Method overloading
C) Operator overloading
D) None of the above
View Answer / Hide Answer

ANSWER: Constructor overloading




9) Constructor does not perform other tasks instead of initialization?

A) True
B) False
View Answer / Hide Answer

ANSWER: False




10) Which constructor is used to provide different values to the distinct objects?

A) Default constructor
B) Parameterized constructor
C) Overloading constructor
D) None of the above
View Answer / Hide Answer

ANSWER: Parameterized constructor




11) The following program is an example for?

class Student{
int id;
String name;

void display(){System.out.println(id+" "+name);}

public static void main(String args[]){
Student s1=new Student();
Student s2=new Student();
s1.display();
s2.display();
}
}

A) Parameterized constructor
B) Default Constructor
C) Overloading Constructor
D) None of the above
View Answer / Hide Answer

ANSWER: Default Constructor




12) If there is no constructor in a class, compiler automatically creates a default constructor?

A) True
B) False
View Answer / Hide Answer

ANSWER: True




13) In java, Method Overloading is possible by changing the return type of the method?

A) True
B) False
View Answer / Hide Answer

ANSWER: False




14) In method overloading the following program is an example for?
class Calculation{
void sum(int a,long b){System.out.println("a method invoked");}
void sum(long a,int b){System.out.println("b method invoked");}

public static void main(String args[]){
Calculation obj=new Calculation();
obj.sum(20,20);//now ambiguity
}
}

A) Method Overloading with Type Promotion in case ambiguity
B) Method Overloading with Type Promotion if matching found
C) Method overloading with Type Promotion
D) None of the above
View Answer / Hide Answer

ANSWER: Method Overloading with Type Promotion in case ambiguity




15) Find whether these two rules correct or not defined by the constructor?
1. Constructor name must be same as its class name.
2. Constructor must have no explicit return type.
A) True
B) False
View Answer / Hide Answer

ANSWER: True




16) If a class has multiple methods by same name but different parameters, it is known as?

A) Constructor overloading
B) Method overloading
C) Operator overloading
View Answer / Hide Answer

ANSWER: Method overloading




17) Which is an Advantage for Method Overloading?

A) Method overloading increases the readability of the program
B) Method overloading does not increases the readability of the program
C) Method overloading increases the reliability of the program
D) Method overloading does not increases the reliability of the program
View Answer / Hide Answer

ANSWER: Method overloading increases the readability of the program




18) Garbage collection only occurs sporadically during the execution of your program?

A) True
B) False
View Answer / Hide Answer

ANSWER: True




19) Which enables some interaction with the garbage collector?

A) java.lang.ref
B) java.lang
C) java.lang.reflect
D) java.math
View Answer / Hide Answer

ANSWER: java.lang.ref




20) Garbage Collection is process of reclaiming the runtime unused memory automatically?

A) True
B) False
View Answer / Hide Answer

ANSWER: True




21) In the following which is a disadvantage for Garbage Collection?

A) It makes java memory efficient because garbage collector removes the unreferenced objects from heap memory
B) It is automatically done by the garbage collector so we don't need to make extra efforts
C) None of the above
View Answer / Hide Answer

ANSWER: None of the above




22) Which method is used to invoke the garbage collector to perform cleanup processing and it is found in System and Runtime classes?

A) gc() method
B) finalize() method
C) q.get() method
D) None of the above
View Answer / Hide Answer

ANSWER: gc() method




23) Which are also known as inner classes?

A) Non-static nested class
B) Static nested class
C) Nested class
D) None of the above
View Answer / Hide Answer

ANSWER: Non-static nested class




24) A class that is declared inside a class but outside a method is known as?

A) Anonymous Inner class
B) Member Inner class
C) Local Inner class
D) Static nested class
View Answer / Hide Answer

ANSWER: Member Inner class




25) Local inner class can access non-final local variable?

A) True
B) False
View Answer / Hide Answer

ANSWER: False




26) For which class the following internal code generated by the compiler?
import java.io.PrintStream;

static class Outer$Inner
{
Outer$Inner(){}

void msg(){
System.out.println((new StringBuilder()).append("data is ")
append(Outer.data).toString());
}

}

A) Static nested class
B) Local Inner class
C) Member Inner class
D) Anonymous Inner class
View Answer / Hide Answer

ANSWER: Static nested class




27) Nested interface must be public if it is declared outside the interface but it cannot have any access modifier if declared within the class?

A) True
B) False
View Answer / Hide Answer

ANSWER: False




28) The Syntax of nested interface which is declared within the?
class class_name{
...
interface nested_interface_name{
...
}
}

A) Interface
B) Class
C) Both A & B
D) None of the above
View Answer / Hide Answer

ANSWER: Class



Post your comment

    Discussion

  • RE: Object-oriented programming with Java Classes and Objects -pankaj kumar (01/30/18)
  • Its so good site to learn
  • RE: Object-oriented programming with Java Classes and Objects -vijay (11/16/15)
  • most usefull.