Classes and Methods
box obj;
a) Memory address of allocated memory of object.
b) NULL
c) Any arbitrary pointer
d) Garbage
a) Box obj = new Box();
b) Box obj = new Box;
c) obj = new Box();
d) new Box obj;
a) malloc
b) alloc
c) new
d) give
a) Every class must contain a main() method.
b) Applets do not require a main() method at all.
c) There can be only one main() method in a program.
d) main() method must be made public.
-
class main_class {
-
public static void main(String args[])
-
{
-
int x = 9;
-
if (x == 9) {
-
int x = 8;
-
System.out.println(x);
-
}
-
}
-
}
a) 9
b) 8
c) Compilation error
d) Runtime error
a) Public method is accessible to all other classes in the hierarchy
b) Public method is accessible only to subclasses of its parent class
c) Public method can only be called by object of its class.
d) Public method can be accessed by calling object of the public class.
-
class box {
-
int width;
-
int height;
-
int length;
-
}
-
class mainclass {
-
public static void main(String args[])
-
{
-
box obj = new box();
-
obj.width = 10;
-
obj.height = 2;
-
obj.length = 10;
-
int y = obj.width * obj.height * obj.length;
-
System.out.print(y);
-
}
-
}
a) 12
b) 200
c) 400
d) 100
-
class box {
-
int width;
-
int height;
-
int length;
-
}
-
class mainclass {
-
public static void main(String args[])
-
{
-
box obj1 = new box();
-
box obj2 = new box();
-
obj1.height = 1;
-
obj1.length = 2;
-
obj1.width = 1;
-
obj2 = obj1;
-
System.out.println(obj2.height);
-
}
-
}
a) 1
b) 2
c) Runtime error
d) Garbage value
a) Function overriding
b) Function overloading
c) Function doubling
d) None of the mentioned
a) All object of a class are allotted memory for the all the variables defined in the class.
b) If a function is defined public it can be accessed by object of other class by inheritation.
c) main() method must be made public.
d) All object of a class are allotted memory for the methods defined in the class.
-
class box {
-
int width;
-
int height;
-
int length;
-
int volume;
-
void volume(int height, int length, int width) {
-
volume = width*height*length;
-
}
-
}
-
class Prameterized_method{
-
public static void main(String args[])
-
{
-
box obj = new box();
-
obj.height = 1;
-
obj.length = 5;
-
obj.width = 5;
-
obj.volume(3,2,1);
-
System.out.println(obj.volume);
-
}
-
}
a) 0
b) 1
c) 6
d) 25
-
class equality {
-
int x;
-
int y;
-
boolean isequal(){
-
return(x == y);
-
}
-
}
-
class Output {
-
public static void main(String args[])
-
{
-
equality obj = new equality();
-
obj.x = 5;
-
obj.y = 5;
-
System.out.println(obj.isequal());
-
}
-
}
a) false
b) true
c) 0
d) 1
-
class box {
-
int width;
-
int height;
-
int length;
-
int volume;
-
void volume() {
-
volume = width*height*length;
-
}
-
}
-
class Output {
-
public static void main(String args[])
-
{
-
box obj = new box();
-
obj.height = 1;
-
obj.length = 5;
-
obj.width = 5;
-
obj.volume();
-
System.out.println(obj.volume);
-
}
-
}
a) 0
b) 1
c) 25
d) 26
-
class area {
-
int width;
-
int length;
-
int volume;
-
area() {
-
width=5;
-
length=6;
-
}
-
void volume() {
-
volume = width*length*height;
-
}
-
}
-
class cons_method {
-
public static void main(String args[])
-
{
-
area obj = new area();
-
obj.volume();
-
System.out.println(obj.volume);
-
}
-
}
a) 0
b) 1
c) 30
d) error
a) int
b) float
c) void
d) None of the mentioned
a) delete
b) free
c) new
d) None of the mentioned
a) finalize()
b) delete()
c) main()
d) None of the mentioned
-
class equality {
-
int x;
-
int y;
-
boolean isequal() {
-
return(x == y);
-
}
-
}
-
class Output {
-
public static void main(String args[])
-
{
-
equality obj = new equality();
-
obj.x = 5;
-
obj.y = 5;
-
System.out.println(obj.isequal); }
-
}
a) false
b) true
c) 0
d) 1
a) Default constructor is called at the time of declaration of the object if a constructor has not been defined.
b) Constructor can be parameterized.
c) finalize() method is called when a object goes out of scope and is no longer needed.
d) finalize() method must be declared protected.
-
class area {
-
int width;
-
int length;
-
int area;
-
void area(int width, int length) {
-
this.width = width;
-
this.length = length;
-
}
-
-
}
-
class Output {
-
public static void main(String args[])
-
{
-
area obj = new area();
-
obj.area(5 , 6);
-
System.out.println(obj.length + " " + obj.width);
-
}
-
}
a) 0 0
b) 5 6
c) 6 5
d) 5 5
a) Methods
b) Constructors
c) All of the mentioned
d) None of the mentioned
a) Polymorphism
b) Abstraction
c) Encapsulation
d) Recursion
-
class overload {
-
int x;
-
int y;
-
void add(int a) {
-
x = a + 1;
-
}
-
void add(int a, int b){
-
x = a + 2;
-
}
-
}
-
class Overload_methods {
-
public static void main(String args[])
-
{
-
overload obj = new overload();
-
int a = 0;
-
obj.add(6);
-
System.out.println(obj.x);
-
}
-
}
a) 5
b) 6
c) 7
d) 8
-
class overload {
-
int x;
-
double y;
-
void add(int a , int b) {
-
x = a + b;
-
}
-
void add(double c , double d){
-
y = c + d;
-
}
-
overload() {
-
this.x = 0;
-
this.y = 0;
-
}
-
}
-
class Overload_methods {
-
public static void main(String args[])
-
{
-
overload obj = new overload();
-
int a = 2;
-
double b = 3.2;
-
obj.add(a, a);
-
obj.add(b, b);
-
System.out.println(obj.x + " " + obj.y);
-
}
-
}
a) 6 6
b) 6.4 6.4
c) 6.4 6
d) 4 6.4
-
class test {
-
int a;
-
int b;
-
test(int i, int j) {
-
a = i;
-
b = j;
-
}
-
void meth(test o) {
-
o.a *= 2;
-
O.b /= 2;
-
}
-
}
-
class Output {
-
public static void main(String args[])
-
{
-
test obj = new test(10 , 20);
-
obj.meth(obj);
-
System.out.println(obj.a + " " + obj.b);
-
}
-
}
a) 10 20
b) 20 10
c) 20 40
d) 40 20
-
class access{
-
public int x;
-
private int y;
-
void cal(int a, int b){
-
x = a + 1;
-
y = b;
-
}
-
}
-
class access_specifier {
-
public static void main(String args[])
-
{
-
access obj = new access();
-
obj.cal(2, 3);
-
System.out.println(obj.x + " " + obj.y);
-
}
-
}
a) 3 3
b) 2 3
c) Runtime Error
d) Compilation Error
-
class static_out {
-
static int x;
-
static int y;
-
void add(int a, int b){
-
x = a + b;
-
y = x + b;
-
}
-
}
-
class static_use {
-
public static void main(String args[])
-
{
-
static_out obj1 = new static_out();
-
static_out obj2 = new static_out();
-
int a = 2;
-
obj1.add(a, a + 1);
-
obj2.add(5, a);
-
System.out.println(obj1.x + " " + obj2.y);
-
}
-
}
a) 7 7
b) 6 6
c) 7 9
d) 9 7
Which of these method of String class is used to obtain character at specified index?
a) char()
b) Charat()
c) charat()
d) charAt()
Which of these keywords is used to refer to member of base class from a sub class?
a) upper
b) super
c) this
d) None of the mentioned
Which of these method of String class can be used to test to strings for equality?
a) isequal()
b) isequals()
c) equal()
d) equals()
Which of the following statements are incorrect?
a) String is a class.
b) Strings in java are mutable.
c) Every string is an object of class String.
d) Java defines a peer class of String, called StringBuffer, which allows string to be altered.
What is the output of this program?
-
class string_class {
-
public static void main(String args[])
-
{
-
String obj = "hello";
-
String obj1 = "world";
-
String obj2 = "hello";
-
System.out.println(obj.equals(obj1) + " " + obj.equals(obj2));
-
}
-
}
a) false false
b) true true
c) true false
d) false true
click to view answer
a
post a comment