0% found this document useful (0 votes)
24 views

Set 3

Uploaded by

golla vyshnavi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Set 3

Uploaded by

golla vyshnavi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Set -3

1.class S{
public static void main(String arg[])
{
Object o1=2.3;
System.out.println(o1.floatValue()+1);
}
}
What is output of above program

A.Compilation error
B.2.4
C.3.3
D.3.4

2.Can an Object of a Child type be assigned to a variable of the parent type? For example.
Card crd;
BirthDay bd= new BirthDay(“Lucinda”,42);
crd = bd; // is this correct?

A.No-there must aways be an exact match between the variable and the object types.
B.No-but a Object of parent type can be assigned to a variable of child type
C.Yes-an object can be assigned to a reference variable of the parent type.
D.Yes-any object can be assigned to any reference variable.

3.Given the code below:


interface Mylnterface {
void doSomething ( ) ;
}
Class MyClass implements MyInterface {
// xx
}
Choose the valid option that can be substituted in Place of xx in the MyClass Class
public void doSomething ( ) ;
void doSomething ( ) {/*valid code fragments */ }
private void doSomething ( ) { /*valid code fragments*/ }
protected void doSomething ( ) { /*valid code fragments */ }

Choose the best option


A.public void dosomething ( ) :
B.void doSomething ( ) {/*valid code fragments */ }
C.private void d0Something ( ){/*valid code fragments */ }
D.protected void doSomething ( ){/*valid code fragments */ }

4. In Junit,it is possible to ignore a test method from testing?

True
False

5. Which statement is true?


A.private methods of a superclass cannot be overridden in subclasses.
B.A subclass can override any method present in a superclass.
C.An overriding method can declare that it throws more exceptions than the method it is overriding.
D.The parameter list of an overriding method must be a subset of the parameter list of the method
that it is overriding.
6. What type parameter must the following method be called with?
int myMethod ( double[] ar )
{
………..
}
A.An empty double array.
B.A reference to an array that contains elements of type double.
C.A reference to an array that contains zero or more elements of type int
D.An array of any length that contajns double and must be named ar.

7. Junit is ________
A.a product trom Jakarta
B.a product trom Apache
C.an Opensource testing framework
D.None of the above

8.What will be the result of attempting to compile and run the following program?
public class Polymorphism {
public static void main(String[]args) {
A refl = new C();
B ref2 = (B) refl;
System.out.println(ref2.f());
}
}
class A { int f() { return 0; ) }
class B extends A { int f() { return 1; } )
class C extends B { int f() { return 2; ) }

A.The program will fail to compile-


B.The program will compile without error, but will throw a ClassCastException when run.
C.The program will compile without error and print 1 when run.
D.The program will compile without error and print 2 when run.

9.Which statement is true?


A.A subclass must define all the methods from the superclass.
B.It is possible for a subclass to define a method with the same name and parameters as a method
defined by the superclass.
C.Aggregation defines a is-a relationship between a superclass and its subclasses.
D.It is possible for classes to be the superclass of each other.

10.Can an abstract class define both abstract methods and non-abstract methods ?
A.No-it must have all one or the other.
B.No-it must have all abstract methods.
D.Yes-the child classes inherit both.

11,what is the main() method special in a Java program?


A.It is where the execution of a Java program starts
B.only the main() method may create Objects.
C.Every class must have a main() method
D.The main() method must be the only Static method in a program

12.
public class Demo (
pubbc static void main(String args[])
{
for(int I=1;I<=5;I++)
{
for(int j=0;j<I;j++)
{
System.out.println(“*”);
}
System.out.println(‘*’);
}
}
}

A. *
**
***
****
*****

B. *****
****
***
**
*

C.Nothing gets printed

D.Compilation error

13.You want to create a table that looks like:


12 -9 8
7 14
-32-1 0
Which of the following is a correct and legal representation of the above table ?

A. double [][] table = {12,-9,8,7,14,-32,-1,0};


B. double [][] table = {12,-9,8},{7,14,0},{-32,-1,0};
C. double [3][] table = {12,-9,8},{7,14},{-32,-1,0};
D. double [][] table = {12,-9,8},{7,14},{-32,-1,0};

14.What is a method's signature?

A.The signature of a method is the name of the method and the type of its return value.
B.The signature of a method is the name of the method and the names of its parameters.
C.The signature of a method is the name of the method and the data types of its parameters.
D.The signature of a method is the name of the method, its parameter list, and its return type.

15.Here is an abstract method defined in the parent:


public abstract int sumlJp ( into arr );
Which of the following is required in a non-abstract child?

A.public abstract int sumUp ( int[] arr ) { ….}


B.public int sumUp ( int[] arr ) { …}
C.public double sumUp ( int[] arr ) {..} .
D.public jnt sumUp ( long[] arr ) { …}
16.How would you declare and initialize the array of fruits
a. String[ ] arrayOfFruits={"apple","mango","orange"};
b. String[ ] arrayOfFruits=("apple","mango","orange");
c. String[ ] arrayOfFruits=["apple","mango","orange"];
d. String[ ] arrayOfFruits=new String{"apple","mango","orange"};

17.What is output of following program


class YY
{
void m1(Integer i1)
{
System.out.println("Integer"+i1.intValue());
}
void m1(int i1)
{
System.out.println(11);
}
}
class A
{
public static void main(String arg[])
{
YY y1=new YY(); y1. m * 1(3) ;
}
}
a.3
b.Integer:3
c.compilation error
d.Runtime Error

18.@SuppressWarnings is an example for Marker Annotation


a.True
b.False

19Given the following:


double[][] things =
{{1.2, 9.0} ,
{9.2, 0.5, 0.0},
{7.3, 7.9, 1.2, 3.9}};
What is the value of things length?
a.2
b.3
c.4
d.9

20which is true about the package statement in java?


a.It can appear anywhere in the file as long as the syntax is correct.
b.It should appear after all the import statements but before the class declaration.
c.There can be more than one package statement.
d.It should be the first non-comment line in the Java source file.

21.which is used for reading objects from files


a.ObjectStream
b.ObjectInputStream
c.ObjectReader
d.FileReader

22.Say that class Rodent has a child class Rat and another child class Mouse. Class Mouse has a child
class PocketMouse. Examine the following
Rodent rod;
Rat rat new Rat();
Mouse mos= new Mouse();
PocketMouse pit new PocketMouse();
Which one of the following will cause a compiler error?
a.rod=rat;
b.rod=mos;
c.pkt=null;
d.pkt=rat;

23.Annotation is a feauture added in package of java


a.java.annotation
b.java.util.annotation
c.java.lang.annotation
d.None of above

24.asserEquals() of jUnit 4.x doesnt use autoboxing


a.True
b.False

25.What will be the result of attempting to compile and run the following program?
public class Polymorphism2 {

public static void main(String[] args) {

A ref1 = new C();


B ref2 =(B) ref1;

System.out.println(ref2.g());

}
}
class A (

private int f() { return 0;} public int g()(return 3;)

class B extends A {

private int f() { return 1;) public int g() { return f();)

class C extends B{

public int f() {return 2;}


}
Choose the best option

The program will compile without error and print 0 when run.

The program will compile without error and print 1 when run.

The program will compile without error and print 2 when run.

The program will compile without error and print 3 when run.

26.what is CLASSPATH?
a.An environment variable which is used by the Java compiler look for the Java source files.
b.An environment variable which is used by the Java compiler and the JVM to look for
the dependent Java class files.
c.An environment variable which stores the path of the Java compiler.
d.An environment variable which stores the path of the Java interpreter.

27.public class MyProgram {


public static void main(String[] args) {
try {
System.out.print("Hello world ");
} finally {
System.out.println("Finally executing");
}
}
}
a.Nothing. The program will not compile because no exceptions are specified.
b.Nothing. The program will not compile because no catch clauses are specified.
c.Hello world.
d.Hello world Finally executing

28.what is value of -32%6?


a.5
b.-5
c.2
d.-2

29.The @Override annotations can be used with


a.variables
b.method declarations
c.packages
d.None of the above
30.import static java.lang.System.*;
import static java.lang.Integer.*;

public class TestStaticImport {


public static void main(String[] args) {
out.println(toHexString(42));
}
}
a.no output will be printed
b.hex value of 42 will be printed
c.compilation error
d.Runtime error

You might also like