Вы находитесь на странице: 1из 42

1) The default value of a static integer variable of a class in Java is,

(a) 0 (b) 1 (c) Garbage value (d) Null € -1.

A) A

2) What will be printed as the output of the following program?

Public class testincr

Public static void main(String args[])

Int I = 0;

I = i++ + I;

System.out.println(“I = ” +i);

(a) I = 0 (b) I = 1 (c) I = 2 (d) I = 3 € Compile-time Error.

A) B

3) Multiple inheritance means,

(a) one class inheriting from more super classes

(b) more classes inheriting from one super class

© more classes inheriting from more super classes

(d) None of the above

€ (a) and (b) above.


A) A

4) Which statement is not true in java language?

(a) A public member of a class can be accessed in all the packages.

(b) A private member of a class cannot be accessed by the methods of the same class.

© A private member of a class cannot be accessed from its derived class.

(d) A protected member of a class can be accessed from its derived class.

€ None of the above.

A) B

5) To prevent any method from overriding, we declare the method as,

(a) Static (b) const (c) final (d) abstract € none of the above.

A) C

6) Which one of the following is not true?

(a) A class containing abstract methods is called an abstract class.

(b) Abstract methods should be implemented in the derived class.

© An abstract class cannot have non-abstract methods.

(d) A class must be qualified as ‘abstract’ class, if it contains one abstract method.

€ None of the above.

A) C
7) The fields in an interface are implicitly specified as,

(a) static only (b) protected (c) private

(d) both static and final € none of the above.

8) What is the output of the following program:

Public class testmeth

Static int I = 1;

Public static void main(String args[])

System.out.println(i+” , “);

M(i);

System.out.println(i);

Public void m(int i)

I += 2;

(a) 1 , 3 (b) 3 , 1 (c) 1 , 1 (d) 1 , 0 € none of the above.

A) C

9) Which of the following is not true?


(a) An interface can extend another interface.

(b) A class which is implementing an interface must implement all the methods of the interface.

© An interface can implement another interface.

(d) An interface is a solution for multiple inheritance in java.

€ None of the above.

A) C

10) Which of the following is true?

(a) A finally block is executed before the catch block but after the try block.

(b) A finally block is executed, only after the catch block is executed.

© A finally block is executed whether an exception is thrown or not.

(d) A finally block is executed, only if an exception occurs.

€ None of the above.

A) C

Java Multiple Choice Questions And Answers

11) Among these expressions, which is(are) of type String?

(a) “0” (b) “ab” + “cd”

© ‘0’

(d) Both (A) and (B) above € (A), (B) and (C) above.

A) D

12) Consider the following code fragment


Rectangle r1 = new Rectangle();

R1.setColor(Color.blue);

Rectangle r2 = r1;

R2.setColor(Color.red);

After the above piece of code is executed, what are the colors of r1 and

R2 (in this order)?

(a) Color.blue

Color.red

(b) Color.blue

Color.blue

© Color.red

Color.red

(c) Color.red

Color.blue

€ None of the above.

A) C

13) What is the type and value of the following expression? (Notice the integer division)

-4 + ½ + 2*-3 + 5.0

(a) int -5 (b) double -4.5

© int -4

(d) Double -5.0 € None of the above.

A) D
13) What is printed by the following statement?

System.out.print(“Hello,\nworld!”);

(a) Hello, \nworld! (b) Hello, world!

(e) “Hello, \nworld!” € None of the above.

A) C

14) Consider the two methods (within the same

class) Public static int foo(int a, String s)

S = “Yellow”;

A=a+2;

Return a;

Public static void bar()

Int a=3;

String s = “Blue”;

A = foo(a,s);

System.out.println(“a=”+a+” s=”+s);

Public static void main(String args[])

Bar();

What is printed on execution of these methods?


(a) a = 3 s = Blue (b) a = 5 s = Yellow (c) a = 3 s = Yellow

(d) a = 5 s = Blue € none of the above.

A) D

15) Which of the following variable declaration would NOT compile in a java program?

(a) Int var; (b) int VAR; (c) int var1; (d) int var_1; € int 1_var;.

A) E

16) Consider the following class definition:

Public class MyClass

Private int value;

Public void setValue(int i){ / code / }

// Other methods…

The method setValue assigns the value of I to the instance field value. What could you write for the
implementation of setValue?

(a) value = I; (b) this.value = I; (c) value == I;

(d) Both (A) and (B) and above € (A), (B) and (C) above.

A) D
17) Which of the following is TRUE?

(a) In java, an instance field declared public generates a compilation error.

(b) int is the name of a class available in the package java.lang

© Instance variable names may only contain letters and digits.

(d) A class has always a constructor (possibly automatically supplied by the java compiler).

€ The more comments in a program, the faster the program runs.

A) D

18) A constructor

(a) Must have the same name as the class it is declared within.

(b) Is used to create objects.

© May be declared private

(d) Both (A) and (B) above

€ (a), (b) and (c) above.

A) E

19) Consider,

Public class MyClass

Public MyClass(){/code/}

// more code…

To instantiate MyClass, you would write?


(a) MyClass mc = new MyClass();

(b) MyClass mc = MyClass();

© MyClass mc = MyClass;

(d) MyClass mc = new MyClass;

€ The constructor of MyClass should be defined as, public void MyClass(){/code/}.

A) A

Java Programming Multiple Choice Questions

Java Multiple Choice Questions 21) What is byte code in the context of Java?

(a) The type of code generated by a Java compiler.

(b) The type of code generated by a Java Virtual Machine.

© It is another name for a Java source file.

(d) It is the code written within the instance methods of a class.

€ It is another name for comments written within a program.

A) A

Java Multiple Choice Questions 22) What is garbage collection in the context of Java?

(a) The operating system periodically deletes all the java files available on the system.

(b) Any package imported in a program and not used is automatically deleted.

© When all references to an object are gone, the memory used by the object is automatically reclaimed.

(d) The JVM checks the output of any Java program and deletes anything that doesn’t make sense.

€ Janitors working for Sun Micro Systems are required to throw away any Microsoft documentation
found in the employees’ offices.
A) C

Java Multiple Choice Questions 23) You read the following statement in a Java program that compiles
and executes.

Submarine.dive(depth);

What can you say for sure?

(a) depth must be an int

(b) dive must be a method.

© dive must be the name of an instance field.

(d) submarine must be the name of a class

€ submarine must be a method.

A) B

Java Multiple Choice Questions 24) The java run time system automatically calls this method while
garbage collection.

(a) finalizer() (b) finalize() (c) finally()

(d) finalized() € none of the above.

A) B

Java Multiple Choice Questions 25) The correct order of the declarations in a Java program is,

(a) Package declaration, import statement, class declaration

(b) Import statement, package declaration, class declaration

© Import statement, class declaration, package declaration


(d) Class declaration, import statement, package declaration

€ Class declaration, package declaration, import statement.

A) A

Java Multiple Choice Questions 26) An overloaded method consists of,

(a) The same method name with different types of parameters

(b) The same method name with different number of parameters

© The same method name and same number and type of parameters with different return type

(d) Both (a) and (b) above

€ (a), (b) and (c) above.

A) D

Java Multiple Choice Questions 27) A protected member can be accessed in,

(a) a subclass of the same package (b) a non-subclass of the same package

© a non-subclass of different package (d) a subclass of different package

€ the same class.

Which is the false option?

A) C

Java Multiple Choice Questions 28) What is the output of the following code:

Class eq

{
Public static void main(String args[])

String s1 = “Hello”;

String s2 = new String(s1);

System.out.println(s1==s2);

(a) True (b) false (c) 0 (d) 1 € Hello.

A) B

Java Multiple Choice Questions 29) All exception types are subclasses of the built-in class

(a) Exception (b) RuntimeException (c) Error

(d) Throwable € None of the above.

A) D

Java Multiple Choice Questions 30) When an overridden method is called from within a subclass, it will
always refer to the version of that method defined by the

(a) Super class

(b) Subclass

© Compiler will choose randomly

(d) Interpreter will choose randomly

€ None of the abvove.

A) B
Java Multiple Choice Questions With Answers

Java Multiple Choice Questions 31) Mark the incorrect statement from the following:

(a) Java is a fully object oriented language with strong support for proper software engineering
techniques

(b) In java it is not easy to write C-like so called procedural programs

© In java language objects have to be manipulated

(d) In java language error processing is built into the language

€ Java is not a language for internet programming.

A) D

Java Multiple Choice Questions 32) In java, objects are passed as

(a) Copy of that object (b) Method called call by value

© Memory address (d) Constructor

€ Default constructor.

A) C

Java Multiple Choice Questions 33) Which of the following is not a component of Java Integrated
Development Environment (IDE)?

(a) Net Beans (b) Borland’s Jbuilder

© Symantec’s Visual Café (d) Microsoft Visual Fox Pro

€ Microsoft Visual J++.

A) C
Java Multiple Choice Questions 34) Identify, from among the following, the incorrect variable name(s).

(a) _theButton (b) $reallyBigNumber

© 2ndName (d) CurrentWeatherStateofplanet

€ my2ndFont.

A) C

Java Multiple Choice Questions 35) Use the following declaration and initialization to evaluate the Java
expressions

Int a = 2, b = 3, c = 4, d = 5;

Float k = 4.3f;

System.out.println( – -b * a + c *d – -);

(a) 21 (b) 24 (c) 28 (d) 26 € 22.

A) B

Java Multiple Choice Questions 36) Use the following declaration and initialization to evaluate the Java
expressions

Int a = 2, b = 3, c = 4, d = 5;

Float k = 4.3f;

System.out.println(a++);
(a) 3 (b) 2 (c) 4 (d) 10 € Synatax error.

A) B

Java Multiple Choice Questions 37) Use the following declaration and initialization to evaluate the Java
expressions

Int a = 2, b = 3, c = 4, d = 5;

Float k = 4.3f;

System.out.println (-2U * ( g – k ) +c);

(a) 6 (b) 3 (c) 2 (d) 1 € Syntax error.

A) E

Java Multiple Choice Questions 38) Use the following declaration and initialization to evaluate the Java
expressions

Int a = 2, b = 3, c = 4, d = 5;

Float k = 4.3f;

System.out.println (c=c++);

(a) 2 (b) 4 (c) 5 (d) 8 € Syntax error.

A) B

Java Multiple Choice Questions 39) Consider the following Java program :
Class IfStatement{

Public static void main(String args[])

Int a=2, b=3;

If (a==3)

If (b==3)

System.out.println(“===============”);

Else

System.out.println(“#################”);

System.out.println(“&&&&&&&&&&&”);

Which of the following will the output be?

(a) ===============

(b) #################

&&&&&&&&&

© &&&&&&&&&&&

(d) ===============

&&&&&&&&&&

€ ################.

A) C

Java Multiple Choice Questions 40) An applet cannot be viewed using


(a) Netscape navigator

(b) Microsoft Internet Explorer

© Sun’ Hot Java Browser

(d) Applet viewer tool which comes, with the Java Development Kit.

€ Jbuilder.

A) D

Use the following Java program for answering question 11 and 12

Class test{

Void meth(int I, int j)

I *= 2;

I /= 2;

Class argumentPassing

Public static void main(String args[])

Test ob = new test();

Int a = 15, b = 20;

System.out.println(“a and b before call :”+ a +” ” + b);

Ob.meth(a,b);

System.out.println(“a and b after call : “+ a + ” ” +b);

}
Core Java Multiple Choice Questions With Answers

41) What would the output be of the above Program – III before and after it is called?

(a) and b before call : 15 20 a and b after call : 30 10

(b) a and b before call : 5 2 a and b after call : 15 20

© a and b before call : 15 20 a and b after call : 15 20

(d) a and b before call : 30 10 a and b after call : 15 20

€ a and b before call : 15 20 a and b after call :

A) C

42) What would the argument passing method be which is used by the above Program – III?

(a) Call by value (b) Call by reference

© Call by java.lang class (d) Call by byte code

€ Call by compiler.

A) A

43) Consider the following program:

Class prob1{

Int puzzel(int n){

Int result;

If (n==1)

Return 1;

Result = puzzel(n-1) * n;
Return result;

Class prob2{

Public static void main(String args[])

Prob1 f = new prob1();

System.out.println(” puzzel of 6 is = ” + f.puzzel(6));

Which of the following will be the output of the above program?

(a) 6 (b) 120 (c) 30 (d) 720 € 12.

A) D

44) The blank space in the following sentence has to be correctly filled :

Members of a class specified as...................are accessible only to methods of that class.

(a) Protected (b) Final (c) Public (d) Private € Static.


A) D

45) Java compiler javac translates Java source code into ………………………

(a) Assembler language (b) Byte code

© Bit code (d) Machine code

€ Platform dependent code.

A) B

46)...................are used to document a program and improve its readability.

(a) System cells (b) Keywords (c) Comments (d) Control structures € Blocks.

A) C

47) In Java, a character constant’s value is its integer value in the.........................character set.

(a) EBCDIC (b) Unicode (c) ASCII (d) Binary € BCD.

A) B

48) In Java, a try block should immediately be followed by one or more....................blocks.

(a) Throw (b) Run (c) Exit (d) Catch € Error.

A) D

49) An abstract data type typically comprises a …………… and a set of..................respectively.
(a) Data representation, classes (b) Database, operations

© Data representation, objects (d) Control structure, operations

€ Data representation, operations.

A) E

50) In object-oriented programming, the process by which one object acquires the properties of
another object is called

(a) Encapsulation (b) Polymorphism (c) Overloading

(d) Inheritance € Overriding.

A) D

Advanced Java Multiple Choice Questions Ans Answers

51) Re-implementing an inherited method in a sub class to perform a different task from the parent
class is called

(a) Binding (b) Transferring (c) Hiding (d) Coupling € extending.

A) E

52) In a class definition, the special method provided to be called to create an instance of that class is
known as a/an

(a) Interpreter (b) Destructor (c) Constructor (d) Object € Compiler.

A) C
53) Consider the following statements about Java packages:

I. Packages don’t provide a mechanism to partition all class names into more
manageable chunks.
II. Packages provide a visibility control mechanism.
III. One of the important properties of a package is that all classes defined inside a
package is accessible by code outside that package.
IV. The .class files for classes declared to be part of a package can be stored in multiple
directories.

Which of them is correct?

(a) Only (I) above (b) Only (II) above

© Only (III) above (d) Only (IV) above

€ All (I), (II), (III) and (IV) above are wrong.

A) B

54) Consider the following statements:

I. A class can be declared as both abstract and final.


II. A class declared as final can be extended by defining a sub-class.
III. Resolving calls to methods dynamically at run-time is called late binding.
IV. The class Object defined by Java need not be a super class of all other classes.

Identify the correct statement from the following:

(a) Both (I) and (II) above (b) Both (III) and (IV) above

© Both (I) and (III) above (d) Both (II) and (IV) above

€ Only (III) above.

A) E
55) Identify, from among the following, the incorrect descriptions related to Java :

(a) Java Virtual Machine translates byte code into its own system’s machine language and runs the
resulting machine code

(b) The arithmetic operations *, /, %, + and – have the same level of precedence

© Comments do not cause any action to be performed during the program execution

(d) All variables must be given a type when they are declared

€ Java variable names are case-sensitive.

A) B

56) Consider the following statement(s) about Java:

I. All white-space characters (blanks) are ignored by the compiler.


II. Java keywords can be used as variable names.
III. An identifier does not begin with a digit and does not contain any spaces.
IV. The execution of Java applications begins at method main.

Which of them is correct?

(a) Both (I) and (III) above (b) Both (II) and (IV) above

© Both (I) and (II) above (d) (III) and (IV) above

€ All (I), (II), (III) and (IV) above.

A) D

57) Consider the following data types in Java :

I. Int II. Boolean III. Double IV. String V. Array.


Which of them are simple data types?

(a) Both (I) and (II) above (b) (I), (II), (III) and (IV) above

© (I), (II) and (III) above (d) (II) and (III) above

€ All (I), (II), (III), (IV) and (V) above.

A) C

58) For what values respectively of the variables gender and age would the Java expression gender == 1
&& age >= 65 become true?

(a) gender = 1, age = 60 (b) gender = 1, age = 50

© gender = 1, age = 65 (d) gender = 0, age = 70

€ gender = 0, age = 55.

A) C

59) Consider the following Java program :

Public class Compute {

Public static void main (string args [ ])

Int result, x ;

X=1;

Result = 0;

While (x < = 10) {

If (x%2 == 0) result + = x ;

++x;
}

System.out.println(result) ;

Which of the following will be the output of the above program?

(a) 55 (b) 30 (c) 25 (d) 35 € 45.

A) B

60) Which of the following statements about Java Threads is correct?

(a) Java threads don’t allow parts of a program to be executed in parallel

(b) Java is a single-threaded language

© Java’s garbage collector runs as a high priority thread

(d) Ready, running and sleeping are three states that a thread can be in during its life cycle

€ Every java application is not multithreaded.

A) D

Core Java Multiple Choice Questions

1) A process that involves recognizing and focusing on the important characteristics of


a situation or object is known as:

(a) Encapsulation (b) Polymorphism

© Abstraction (d) Inheritance

€ Object persistence.
A) C

2) Which statement is true regarding an object?

(a) An object is what classes instantiated are from

(b) An object is an instance of a class

© An object is a variable

(d) An object is a reference to an attribute

€ An object is not an instance of a class.

A) B

3) In object-oriented programming, composition relates to

(a) The use of consistent coding conventions

(b) The organization of components interacting to achieve a coherent, common behavior

© The use of inheritance to achieve polymorphic behavior

(d) The organization of components interacting not to achieve a coherent common behavior

€ The use of data hiding to achieve polymorphic behavior.

A) B

4) In object-oriented programming, new classes can be defined by extending existing


classes. This is an example of:

(a) Encapsulation (b) Interface

© Composition (d) Inheritance € Aggregation.


A) D

5) Which of the following does not belong: If a class inherits from some other class,
it should

(a) Make use of the parent class’s capabilities

(b) Over-ride or add the minimum to accomplish the derived class’ purpose

© Over-ride all the methods of its parent class

(d) Make sure the result “IS-A-KIND-OF” its base class

€ Make sure the result “contains” its base class.

A) C

6) Object-oriented inheritance models the

(a) “is a kind of” relationship

(b) “has a” relationship

© “want to be” relationship

(d) inheritance does not describe any kind of relationship between classes

€ “contains” of relationship.

A) A

7) The wrapping up of data and functions into a single unit is called

(a) Encapsulation (b) Abstraction

© Data Hiding (d) Polymorphism € Message passing.

A) A
8) Polymorphism

(a) Is not supported by Java

(b) Refers to the ability of two or more objects belonging to different classes to respond to exactly the
same message in different class-specific ways

© Simplifies code maintenance

(d) Not simplifies code maintenance

€ Refers to the ability of two or more objects belonging to different classes to respond to exactly the
same message in different class-specific ways and simplifies code maintenance.

A) E

9) In object-oriented programming, new classes can be defined by extending existing


classes. This is an example of:

(a) Encapsulation (b) Interface (c) Composition

(d) Inheritance € Aggregation.

A) D

10) Given a class named student, which of the following is a valid constructor declaration for
the class?

(a) Student (student s) { } (b) Student student ( ) { }

© Private final student ( ) { } (d) Void student ( ) { }

€ Static void student(){ }.

A) A
Core Java Multiple Choice Questions With Answers

11) What is garbage collection in the context of Java?

(a) The operating system periodically deletes all of the java files available on the system.

(b) Any package imported in a program and not used is automatically deleted.

© When all references to an object are gone, the memory used by the object is automatically reclaimed.

(d) The JVM checks the output of any Java program and deletes anything that doesn’t make sense.

€ When all references to an object are gone the memory used by the object is not reclaimed.

A) C

12) The concept of multiple inheritances is implemented in Java by

I. Extending two or more classes.


II. Extending one class and implementing one or more interfaces.
III. Implementing two or more interfaces.

(a) Only (II) (b) (I) and (II) (c) (II) and (III)

(d) Only (I) € Only (III).

A) C

13) In Java, declaring a class abstract is useful

(a) To prevent developers from further extending the class

(b) When it doesn’t make sense to have objects of that class

© When default implementations of some methods are not desirable

(d) To force developers to extend the class not to use its capabilities

€ When it makes sense to have objects of that class.


A) B

14) What is the error in the following class definitions?

Abstract class xy

Abstract sum (int x, int y) { }

(a) Class header is not defined properly.

(b) Constructor is not defined.

© Method is not defined properly

(d) Method is defined properly

€ No error.

A) C

15) Which of these field declarations are legal within the body of an interface?

(a) Private final static int answer = 42 (b) public static int answer=42

© final static answer =42 (d) int answer

€ No error.

A) B

16) A package is a collection of

(a) Classes (b) Interfaces (c) Editing tools


(d) Classes and interfaces € Editing tools and interfaces.

A) D

17) A method within a class is only accessible by classes that are defined within the same
package as the class of the method. Which one of the following is used to enforce
such restriction?

(a) Declare the method with the keyword public

(b) Declare the method with the keyword private

© Declare the method with the keyword protected

(d) Do not declare the method with any accessibility modifiers

€ Declare the method with the keyword public and private.

A) D

18) Basic Java language functions are stored in which of the following java package?

(a) Java.lang (b) java.io (c) java.net (d) java.util € java.awt

A) A

19) Which of the following is a member of the java.lang package?

(a) List (b) Queue (c) Math (d) Stack € Process.

A) B

20) Which of the following has a method names flush( )?


(a) Input stream (b) Output Stream

© Reader stream (d) Input reader stream

€ Input output stream.

A) B

Core Java Multiple Choice Questions And Answers

Core Java Multiple Choice Questions # 21) What is the fundamental unit of information of writer
streams?

(a) Characters (b) Bytes

© Files (d) Records € Information.

A) A

Core Java Multiple Choice Questions # 22) File class is included in which package?

(a) java.io package (b) java.lang package

© java.awt package (d) java.net.package

€ java.util.package.

A) A

Core Java Multiple Choice Questions # 23) Given the code

String s1 = ” yes” ;

String s2 = ” yes ” ;

String s3 = new String ( s1);


Which of the following would equate to true?

(a) S1 == s2 (b) s1 = s2 (c) s3 == s1 (d) s3=s1 € s1!=s2.

A) A

Core Java Multiple Choice Questions # 24) URL stands for

(a) Universal reader locator (b) Universal reform loader

© Uniform resource loader (d) Uniform resource locator

€ Uniform reader locator.

A) D

Core Java Multiple Choice Questions # 25) What is the sequence of major events in the life of an applet?

(a) init, start, stop, destroy (b) start, init , stop , destroy

© init, start , destroy, stop (d) init, start, destroy

€ destroy, start, init, stop.

A) A

Core Java Multiple Choice Questions # 26) Which of the following is true in regard to applet execution?

(a) Applets loaded from the same computer where they are executing have the same restrictions as
applets loaded from the network.

(b) Applets loaded and executing locally have none of the restrictions faced by applets that get loaded
from the network.
© Applets loaded and executing locally have some restrictions faced by applets that get loaded from the
network.

(d) Applets cant react to user input and change dynamically

€ Applets can be run independently.

A) B

Core Java Multiple Choice Questions # 27) What is the return type of the method getID() defined in
AWTEvent class

(a) Int (b) long (c) Object (d) Component € float.

A) A

Core Java Multiple Choice Questions # 28) Which of the following events will cause a thread to die?

(a) The method sleep( ) is called

(b) The method wait( ) is called

© Execution of the start( ) method ends

(d) Execution of the run( ) method ends

€ Execution of the run() method is called.

A) D

Core Java Multiple Choice Questions # 29) What will be the result of the expression 13 & 25?

(a) 38 (b) 25 (c) 9 (d) 12 € 21.

A) C
Core Java Multiple Choice Questions # 30) Which of the following statements are true regarding the
finalize( ) method?

(a) The finalize ( ) method must be declared with protected accessibility

(b) The compiler will fail to compile the code that explicitly tries to call the finalize( ) method

© The body of the finalize ( ) method can only access other objects that are eligible for garbage
collection

(d) The finalize ( ) method can be overloaded

€ The finalize() method cant be overloaded.

A) D

Core Java Objective Questions And Answers

Core Java Multiple Choice Questions # 31) Which one of these is a valid method declaration?

(a)

Void method1

(b)

Void method2()

Void method3(void)

(d)

Method4()

Methods(void).

A) B
Core Java Multiple Choice Questions # 32) Given a class named Book, which one of these is a valid
constructor declaration for the class?

(a)

Book(Book b) { }

(b)

Book Book() { }

Private final Book() { }

(d)

Void Book() { }

Abstract Book() { }.

A) A

Core Java Multiple Choice Questions # 33) What will be the result of attempting to compile the following
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)

}
(a)

A compilation ERROR will occur at (1), since constructors cannot specify a return value

(b)

A compilation error will occur at (2), since the class does not have a default constructor

A compilation error will occur at (3), since the class does not have a constructor which takes one
argument of type int

(d)

The program will compile correctly

The program will compile and execute correctly.

A) C

Core Java Multiple Choice Questions # 34) Given the following class, which of these is valid way of
referring to the class from outside of the package net.basemaster?

Package net.basemaster;

Public class Base {

// . . .

Select the correct answer.

(a)

By simply referring to the class as Base

(b)

By simply referring to the class as basemaster.Base

By simply referring to the class as net.basemaster.Base


(d)

By simply referring to the class as net.Base

By importing with net.* and referring to the class as basemaster.Base.

A) C

Core Java Multiple Choice Questions # 35) Which one of the following class definitions is a valid
definition of a class that cannot be instantiated?

(a)

Class Ghost

Abstract void haunt();

(b)

Abstract class Ghost

Void haunt();

Abstract class Ghost

Void haunt() { };

(d)
Abstract Ghost

Abstract void haunt();

Static class Ghost

Abstract haunt();

A) C

Core Java MCQ Questions With Answers

36) Which one of the following class definitions is a valid definition of a class that cannot be extended?

(a)

Class Link { }

(b)

Abstract class Link { }

Native class Link { }

(d)

Static class Link { }

Final class Link { }.

A) E
37) Given the following definition of a class, which fields are accessible from outside the package
com.corporation.project?

Package com.corporation.project;

Public class MyClass

Int I;

Public int j;

Protected int k;

Private int l;

Select the correct answer.

(a)

Field I is accessible in all classes in other packages

(b)

Field j is accessible in all classes in other packages

Field k is accessible in all classes in other packages

(d)

Field l is accessible in all classes in other packages

Field l is accessible in subclasses only in other packages.

A) B

38) How restrictive is the default accessibility compared to public, protected, and private accessibility?

(a)
Less restrictive than public

(b)

More restrictive than public, but less restrictive than protected

More restrictive than protected, but less restrictive than private

(d)

More restrictive than private

Less restrictive than protected from within a package, and more restrictive than protected from outside
a package.

A) C

39) Which statement is true about accessibility of members?

(a)

Private members are always accessible from within the same package

(b)

Private members can only be accessed by code from within the class of the member

A member with default accessibility can be accessed by any subclass of the class in which it is defined

(d)

Private members cannot be accessed at all

Package/default accessibility for a member can be declared using the keyword default.

A) B

40) Which of the following is true about the use of modifiers?


(a)

If no accessibility modifier (public, protected, and private) is specified for a member declaration, the
member is only accessible for classes in the package of its class and subclasses of its class anywhere

(b)

You cannot specify accessibility of local variables. They are only accessible within the block in which they
are declared

Subclasses of a class must reside in the same package as the class they extend

(d)

Local variables can be declared static

None of the above.

A) B

Вам также может понравиться