0% found this document useful (0 votes)
66 views72 pages

CS201 PreMidsem Merged

The document appears to be a summary of a student's performance on a mid-semester exam for a computer science course. The student answered 20 multiple choice questions, getting 11 questions correct and earning a grade of 77%. The questions covered topics like objects, classes, inheritance, encapsulation, and other core object-oriented programming concepts.

Uploaded by

Ravindra Singh
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)
66 views72 pages

CS201 PreMidsem Merged

The document appears to be a summary of a student's performance on a mid-semester exam for a computer science course. The student answered 20 multiple choice questions, getting 11 questions correct and earning a grade of 77%. The questions covered topics like objects, classes, inheritance, encapsulation, and other core object-oriented programming concepts.

Uploaded by

Ravindra Singh
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/ 72

Dashboard /

Courses /
Autumn 2021-22 /
BTech Sem-3 /
CS 201 /
Mid Semester Examination /
Pre-mid Semester Quiz Test

Started on Thursday, 21 October 2021, 11:23 AM


State Finished
Completed on Thursday, 21 October 2021, 11:55 AM
Time taken 31 mins 17 secs
Marks 27.00/35.00
Grade 7.71 out of 10.00 (77%)

Question 1
Correct

Mark 1.00 out of 1.00

Which of the following statements is true concerning objects and/or classes? 

a. An object is an instance of a class.


b. A class encapsulates only data.

c. A class is an instance of an object.

d. An object encapsulates only data.

The correct answer is:


An object is an instance of a class.

Question 2
Correct

Mark 1.00 out of 1.00

A programmer wants to make a member of a class visible only to all subclasses regardless of what package they are in. Which of the
following access specifiers can be used.

a. Private 

b. Default

c. Protected 

d. Public

The correct answer is:


Protected
Question 3
Incorrect

Mark 0.00 out of 1.00

Two methods cannot have the same name in Java.

Select one:
True 

False

The correct answer is 'False'.

Question 4
Correct

Mark 1.00 out of 1.00

Predict the output of the following Java program?


class Test 

  int i;

class Main 
{

   public static void main(String args[]) { 


     Test t; 

     System.out.println(t.i); 
}

a. Run time error

b. Garbage Value

c. Compiler Error 

d. 0

The correct answer is:


Compiler Error
Question 5
Correct

Mark 1.00 out of 1.00

What would be the output of the following code;


public class check

{
public static void main(String args[])

{
boolean b = true;

System.out.println("CSE");
if (!b)

return;

System.out.println("ESC");
}

a. ESC

b. CSE followed by ESC 

c. CSE

d. Compiler Error

The correct answer is:


CSE followed by ESC

Question 6
Correct

Mark 1.00 out of 1.00

Does Constructors create an Object?

a. Yes

b. No 

The correct answer is:


No
Question 7
Correct

Mark 1.00 out of 1.00

The benefits of object-oriented modeling are which of the following?

a. Reusability of analysis, design, and programming results 

b.
The ability to tackle more challenging problems 

c. All of the above 

d.
Improved communication between users, analysts, etc. 

The correct answer is: All of the above

Question 8
Correct

Mark 1.00 out of 1.00

Aggregation is which of the following?

a. Expresses an is-a relationship and is a weaker form of an association relationship.

b. Expresses a part-of relationship and is a weaker form of an association relationship.

c. Expresses a part-of relationship and is a stronger form of an association relationship.


d. Expresses an is-a relationship and is a stronger form of an association relationship.

The correct answer is:


Expresses a part-of relationship and is a stronger form of an association relationship.
Question 9
Correct

Mark 1.00 out of 1.00

Predict the output of the following Java program?

class demo
{

    int a, b;
     demo()

    {

        a = 10;
        b = 20;

    }
    

    public void print()


    {

        System.out.println ("a = " + a + " b = " + b + "n");


    }

 
class Test

{
 

    public static void main(String[] args)


    {

        demo obj1 = new demo();

        demo obj2 = obj1;


 

        obj1.a += 1;
        obj1.b += 1;

 
        System.out.println ("values of obj1 : ");

        obj1.print();
        System.out.println ("values of obj2 : ");

        obj2.print();

 
    }

a. Compiler Error

b.
values of obj1: a = 11 b = 21 
values of obj2: a = 10 b = 20

c. values of obj1: a = 11 b = 20 

values of obj2: a = 10 b = 21

d. values of obj1: a = 11 b = 21  

values of obj2: a = 11 b = 21

The correct answer is:

values of obj1: a = 11 b = 21 

values of obj2: a = 11 b = 21

Question 10
Incorrect

Mark 0.00 out of 1.00

The object-oriented development life cycle is which of the following?

a. Analysis, design, and implementation steps in any order and going through the steps no more than one time.

b. Analysis, design, and implementation steps in the given order and going through the steps no more than one time.

c. Analysis, design, and implementation steps in any order and using multiple iterations

d. Analysis, design, and implementation steps in the given order and using multiple iterations.

The correct answer is:


Analysis, design, and implementation steps in the given order and using multiple iterations.

Question 11
Incorrect

Mark 0.00 out of 1.00

How many arguments are required in the definition of an overloaded unary operator?

a. 1 

b. 3

c. 2

d. None

The correct answer is:


None
Question 12
Correct

Mark 1.00 out of 1.00

It is an error to have a method with the same signature in both the super class and its subclass

Select one:
True

False 

The correct answer is 'False'.

Question 13
Correct

Mark 1.00 out of 1.00

Consider the following two statements: 


(a) A publicly derived class is a subtype of its base class. 

(b) Inheritance provides for code reuse.

a. Statement (a) is correct and (b) is incorrect

b. Neither of the statements (a) and (b) are correct

c. 
Both the statements (a) and (b) are correct.

d. Statement (a) is incorrect and (b) is correct

The correct answer is:


Both the statements (a) and (b) are correct.

Question 14
Correct

Mark 1.00 out of 1.00

A protected member of a superclass, when inherited into a subclass becomes which of the following types

a. Public

b. Default

c. Private 

d. Protected

The correct answer is:


Private

Question 15
Correct

Mark 1.00 out of 1.00

Which of the following characteristics of an object-oriented programming language restricts behaviour so that an object can only
perform actions that are defined for its class?

a. Encapsulation 

b. Polymorphism

c. Dynamic binding

d. Inheritance

The correct answer is:


Encapsulation

Question 16
Correct

Mark 1.00 out of 1.00

Packages are a collection of

a. Classes

b. Classes and Interfaces 

c. All of the above

d. Attributes

The correct answers are:


Classes,
Classes and Interfaces
Question 17
Correct

Mark 1.00 out of 1.00

What best describes the purpose of a class’s constructor?

a. Initialize the fields in the object.


b. Determines the amount of space needed for an object and creates the object.

c. Names the new object

d. None of the above

The correct answer is:


Initialize the fields in the object.

Question 18
Incorrect

Mark 0.00 out of 1.00

A normal method in a subclass must always invoke its super class constructor in its first statement

a. False

b. True 

c. Methodology not possible

d. Depends upon the Java compiler

The correct answer is:


Methodology not possible
Question 19
Incorrect

Mark 0.00 out of 1.00

In multilevel inheritance, the last subclass inherits all methods and variables of

a. Few classes selected based on the Java compiler version


b. All classes above it

c. None of the above

d. The immediate Superclass

The correct answer is:


The immediate Superclass

Question 20
Correct

Mark 1.00 out of 1.00

A bookstore is working on an on-line ordering system. For each type of published material (books, movies, audio tapes) they need
to track the id, title, author(s), date published, and price. Which of the following would be the best design?

a. Create one class BookStore with the requested fields plus type.

b. Create classes for each

c.
Create classes Book, Movie, and AudioTape with the requested fields.

d. Create the class PublishedMaterial with children classes of Book, Movie, and AudioTape. 

e. Create one class PublishedMaterial with the requested fields plus type.

The correct answer is:


Create the class PublishedMaterial with children classes of Book, Movie, and AudioTape.

Question 21
Incorrect

Mark 0.00 out of 1.00

The concept of multiple inheritance is implemented in C++ by

a. All of the above 

b. Extending one class and implementing one or more interfaces

c. Implementing two or more interfaces

d. Extending two or more classes

The correct answer is:


Extending two or more classes

Question 22
Correct

Mark 1.00 out of 1.00

We can overload methods with differences only in their return type

Select one:
True

False 

The correct answer is 'False'.

Question 23
Correct

Mark 1.00 out of 1.00

Default (friendly) members of a super class are accessible to the subclass members, where both the classes are in different packages

Select one:
True

False 

The correct answer is 'False'.


Question 24
Incorrect

Mark 0.00 out of 1.00

When would you use a private constructor?

a. If you want to protect your class’s members from outside modification


b. If you want to disallow instantiation of that class from outside that class

c. When you get bored with public

d. Never, it's not allowed

The correct answer is:


If you want to disallow instantiation of that class from outside that class
Question 25
Correct

Mark 1.00 out of 1.00

What would be the output of the following Java program:

class one1
{

one1()
{

System.out.println("Hello");
}

}
class two2 extends one1

public class check {

public static void main(String[] args)


{

two2 t = new two2();

a. Compiler Error. 

b. Blank. No output.

c. Hello Hello

d. Hello 

The correct answer is:


Hello

Question 26
Correct

Mark 1.00 out of 1.00

How many different types of access specifiers are possible in Java?

Answer: 4 

The correct answer is: 4


Question 27
Correct

Mark 1.00 out of 1.00

What would be the output of the following code?

public class check


{

public static void main(String args[])


{

boolean b = true;

System.out.println("CSE");
return;

System.out.println("ESC");
}

a. ESC

b. Compiler Error 

c. CSE

d. CSE followed by ESC

The correct answer is:


Compiler Error
Question 28
Correct

Mark 1.00 out of 1.00

Abstraction and encapsulation are fundamental principles that underlie the object-oriented approach to software development. What can
you say about the following two statements;

I. Abstraction allows us to focus on what something does without considering the complexities of how it works.
II. Encapsulation allows us to consider complex ideas while ignoring irrelevant details that would confuse us.

a. Only I is correct.

b. Both I and II are correct.

c. 
Neither I nor II is correct.

d. Only II is correct.

The correct answer is:

Neither I nor II is correct.

Question 29
Incorrect

Mark 0.00 out of 1.00

Any class may be inherited by another class in the same package

a. Depends upon the specific Access specifier

b. True

c. False 

d. Depends upon the Java version

The correct answers are:


True,

Depends upon the specific Access specifier


Question 30
Correct

Mark 1.00 out of 1.00

Operator overloading is

a. Making C++ operators work with objects

b. Giving new meanings to existing C++ operators



c. Making new C++ operators

d. Giving C++ operators more operands than usual

The correct answers are:


Making C++ operators work with objects,
Giving new meanings to existing C++ operators

Question 31
Correct

Mark 1.00 out of 1.00

Composition is a stronger form of which of the following?

a. All of the above

b. Aggregation

c. Encapsulation

d. Inheritance

The correct answer is:


Aggregation
Question 32
Correct

Mark 1.00 out of 1.00

When does method overloading is determined?

a. Execution time

b. Run time

c. Compile time 

d. Coding time

The correct answer is:


Compile time

Question 33
Correct

Mark 1.00 out of 1.00

Protected members of a super class are accessible to the subclass members, where both the classes are in the same package.

Select one:
True 

False

The correct answer is 'True'.


Question 34
Correct

Mark 1.00 out of 1.00

It is desired to design an object-oriented employee record system for a company. Each employee has a name, unique id and salary.
Employees belong to different categories and their salary is determined by their category. The functions to get Name, getld and
compute salary are required. Given the class hierarchy below, possible locations for these functions are;

i. getld is implemented in the superclass

ii. getld is implemented in the subclass


iii. getName is an abstract function in the superclass

iv. getName is implemented in the superclass


v. getName is implemented in the subclass

vi. getSalary is an abstract function in the superclass


vii. getSalary is implemented in the superclass

viii. getSalary is implemented in the subclass

CHOOSE THE BEST DESIGN AMONG THE FOLLOWING OPTIONS;

a. (i), (iv), (vi), (viii)


b. (i), (iii), (v), (vi), (viii)

c. (ii), (v), (viii)

d. (i), (iv), (vii)

The correct answer is:


(i), (iv), (vi), (viii)

Question 35

Correct

Mark 1.00 out of 1.00

Private member of a class is visible to

a. Same class 

b. Everyone

c. Same Package

d. Subclass

The correct answer is:


Same class
◄ Weekly Quiz 2

Jump to...

Mid Semester Online Examination ►


Dashboard /
Courses /
Autumn 2021-22 /
BTech Sem-3 /
CS 201 /
Mid Semester Examination /
Mid Semester Online Examination

Started on Wednesday, 10 November 2021, 9:04 AM


State Finished
Completed on Wednesday, 10 November 2021, 9:39 AM
Time taken 35 mins 21 secs
Marks 27.00/35.00
Grade 7.71 out of 10.00 (77%)

Question 1
Correct

Mark 1.00 out of 1.00

Which of the following statements are True?

a. Each object of a class has its own copy of each non-static member variable.

b. All methods in a class are implicitly passed a 'this' parameter when called.

c. A static method can call other non-static methods in the same class by using the 'this' keyword.

d. Instance methods may access local variables of static methods.

e. A class may contain both static and non-static variables and both static and nonstatic methods.

The correct answers are:


A class may contain both static and non-static variables and both static and nonstatic methods.,

Each object of a class has its own copy of each non-static member variable.
Question 2
Correct

Mark 1.00 out of 1.00

Which of the following is TRUE about Interfaces in Java,

1) An interface can contain the following type of members.


....public, static, final fields (i.e., constants) 

....default and static methods with bodies

2) An instance of the interface can be created.

3) A class can implement multiple interfaces.

4) Many classes can implement the same interface.

a. 1, 2, and 4

b. 1, 3, and 4 

c. 1, 2, 3, and 4

d. 2, 3, and 4

The correct answer is:


1, 3, and 4
Question 3
Incorrect

Mark 0.00 out of 1.00

 Which of the following is correct related to the below program,

class Base {

  public final void show() {


       System.out.println("Base::show() called");

    }
}

class Derived extends Base {


    public void show() { 

       System.out.println("Derived::show() called");

    }
}

public class Main {


    public static void main(String[] args) {

        Base b = new Derived();


        b.show();

    }

a. Derived::show() called

b. Compiler Error

c. Exception

d. Base::show() called

The correct answer is:


Compiler Error
Question 4
Correct

Mark 1.00 out of 1.00

What will be the output of the following Java code?

class A
   {

       public int i;
       private int j;

   }   

   class B extends A
   {

       void display()
       {

           super.j = super.i + 1;
           System.out.println(super.i + " " + super.j);

       }
   }   

   class inheritance

  {
       public static void main(String args[])

       {
           B obj = new B();

           obj.i=1;
           obj.j=2;  

           obj.display();    

       }
  }

a. 2   2

b. 3   3

c. Runtime Error

d. Compilation Error 

The correct answer is:


Compilation Error
Question 5
Incorrect

Mark 0.00 out of 1.00

A normal method in a subclass must always invoke its super class constructor in its first statement

a. True

b. False 

c. Depends upon the Java compiler

d. Methodology not possible

The correct answer is:


Methodology not possible

Question 6
Incorrect

Mark 0.00 out of 1.00

Class A is extending Class B. Which of the following keywords is used inside Class A to call the constructor of Class A.

a. super 

b. static

c. this

d. final

The correct answer is:


this

Question 7
Correct

Mark 1.00 out of 1.00

Which of the following characteristics of an object-oriented programming language restricts behaviour so that an object can only
perform actions that are defined for its class?

a. Dynamic binding

b. Polymorphism

c. Inheritance

d. Encapsulation 

The correct answer is:


Encapsulation
Question 8
Correct

Mark 1.00 out of 1.00

Abstract class can have constructors and static methods?

a. Abstract class cannot have constructors but can not have static methods

b. True 

c. Abstract class can have constructors but can not have static methods

d. False

The correct answer is:


True

Question 9
Incorrect

Mark 0.00 out of 1.00

What will be the output of the following class?

class B 
{

   int b; 
   public B(int b) 

    { 
       b = b; 

     } 

   public static void main (String[] args) 


    { 

       B x = new B(10); 


     System.out.println("x.b :"+x.b);

   }
}

a. 0, 10

b. 0

c. 10 

d. 20

The correct answer is:


0
Question 10
Correct

Mark 1.00 out of 1.00

Abstract class support _____________ inheritance in Java.

a. Multilevel Inheritance

b. Multiple Inheritance

The correct answer is:


Multilevel Inheritance

Question 11
Incorrect

Mark 0.00 out of 1.00

Abstraction and encapsulation are fundamental principles that underlie the object-oriented approach to software development. What can
you say about the following two statements;

I. Abstraction allows us to focus on what something does without considering the complexities of how it works.

II. Encapsulation allows us to consider complex ideas while ignoring irrelevant details that would confuse us.

a. Only II is correct.

b.
Neither I nor II is correct.

c. Only I is correct.

d. Both I and II are correct.


The correct answer is:


Neither I nor II is correct.

Question 12
Correct

Mark 1.00 out of 1.00

A programmer wants to make a member of a class visible only to all subclasses regardless of what package they are in. Which of the
following access specifiers can be used.

a. Protected 

b. Default

c. Private 

d. Public

The correct answer is:


Protected

Question 13
Correct

Mark 1.00 out of 1.00

Composition is a stronger form of which of the following?

a. All of the above

b. Aggregation

c. Inheritance

d. Encapsulation

The correct answer is:


Aggregation
Question 14
Incorrect

Mark 0.00 out of 1.00

How many instance initializers are in this code?

public class Bowling {


 { 

     System.out.println(); 

 }
 public Bowling () {

    System.out.println();
 }

 static { 
    System.out.println(); 

 }

 { 
     System.out.println(); 

 }
}

a. Two

b. One

c. None

d. Three 

The correct answer is:


Two
Question 15
Correct

Mark 1.00 out of 1.00

What is the output of this program,

class check {

public static void main(String[] args)


{

int x = 20;

System.out.println(x);
}

static
{

int x = 10;
System.out.print(x + " ");

}
}

a. 20   10

b. 10    20 

c. 20    20

d. 10    10

The correct answer is:


10    20

Question 16
Correct

Mark 1.00 out of 1.00

What best describes the purpose of a class’s constructor?

a. None of the above

b.
Determines the amount of space needed for an object and creates the object.

c. Initialize the fields in the object.


d. Names the new object

The correct answer is:


Initialize the fields in the object.
Question 17
Correct

Mark 1.00 out of 1.00

What is the output of the following Java program,

class Main {
 public static void main(String args[]){

   final int i;
   i = 20;

   System.out.println(i);

 }
}

a. 0

b. Garbage value

c. Compilation Error

d. 20 

The correct answer is:


20

Question 18
Correct

Mark 1.00 out of 1.00

Class A is extending Class B. Which of the following keyword is used inside Class A to call the constructor of Class B

a. static

b. this

c. super 

d. final

The correct answer is:


super
Question 19
Incorrect

Mark 0.00 out of 1.00

In the following code, how many times ‘this’ would be created,

class A 
 {

   public static void main (String[] args) 

    { 
      A x = new A();

      A y = new A();


    }

a. 1 

b. 2

c. 3

d. 0

The correct answer is:


2

Question 20
Incorrect

Mark 0.00 out of 1.00

Any class may be inherited by another class in the same package

a. Depends upon the specific Access specifier

b. False 

c. True

d. Depends upon the Java version

The correct answers are:


True,

Depends upon the specific Access specifier


Question 21
Correct

Mark 1.00 out of 1.00

Which keyword is used for accessing the features of a package?

a. Import 

b. Export

c. Extends

d. Package

The correct answer is:


Import

Question 22
Correct

Mark 1.00 out of 1.00

Two methods cannot have the same name in Java.

Select one:
True

False 

The correct answer is 'False'.


Question 23
Correct

Mark 1.00 out of 1.00

What would be the output of the following program?

abstract class demo


{

public int a;
demo()

a = 10;
}

abstract public void set();


abstract final public void get();

class Test extends demo


{

public void set(int a)

{
this.a = a;

final public void get()


{

System.out.println("a = " + a);


}

public static void main(String[] args)

{
Test obj = new Test();

obj.set(20);
obj.get();

}
}

a. a = 10

b. Compilation Error 

c. NULL

d. a = 20

The correct answer is:


Compilation Error
Question 24
Correct

Mark 1.00 out of 1.00

What is the output of the following code,

class TestRunner {  


  static public int succeeded;

  static public int failed;


  

  public TestRunner() {    

  }
  

  public TestRunner(int s, int f) {


    succeeded=s; failed=f;

  }
  

  public void display() {


      System.out.println(succeeded + " " + failed);

  }

class check {

  public static void main(String[] args) {


    TestRunner tr = new TestRunner(1, 99);

    TestRunner.succeeded = 99;

    tr.display();
  }

a. 0   0

b. 1   99

c. 99   99 

d. 99   0

The correct answer is:


99   99
Question 25
Correct

Mark 1.00 out of 1.00

Static methods can be overloaded.

Select one:
True 

False

The correct answer is 'True'.

Question 26
Correct

Mark 1.00 out of 1.00

Consider the following two statements: 


(a) A publicly derived class is a subtype of its base class. 

(b) Inheritance provides for code reuse.

a. Both the statements (a) and (b) are correct. 

b. Statement (a) is incorrect and (b) is correct

c. Statement (a) is correct and (b) is incorrect

d. Neither of the statements (a) and (b) are correct

The correct answer is:


Both the statements (a) and (b) are correct.

Question 27
Correct

Mark 1.00 out of 1.00

Which of the following is FALSE about abstract classes in Java

a. Abstract classes can have constructors 

b.
A class can be made abstract without any abstract method 

c. If we derive an abstract class and do not implement all the abstract methods, then the derived class should also be marked as
abstract using 'abstract' keyword

d. A class can inherit from multiple abstract classes. 

The correct answer is:


A class can inherit from multiple abstract classes.

Question 28
Correct

Mark 1.00 out of 1.00

Given that Student is a class, how many reference variables and objects are created by the following code?

Student studentName, studentId;  


studentName = new Student();  

Student stud_class = new Student(); 

a. One reference variable and two objects are created.

b. Two reference variables and two objects are created.

c. Three reference variables and two objects are created.



d. Three reference variables and three objects are created.

The correct answer is:


Three reference variables and two objects are created.

Question 29
Correct

Mark 1.00 out of 1.00

Which of the following cannot have ‘this’ keyword inside it

a. Constructors

b. Static methods and blocks 

c. Non static methods

The correct answer is:


Static methods and blocks

Question 30
Correct

Mark 1.00 out of 1.00

A protected member of a superclass, when inherited into a subclass becomes which of the following types

a. Protected

b. Default

c. Public

d. Private 

The correct answer is:


Private
Question 31
Correct

Mark 1.00 out of 1.00

What should be the execution order, if a class has a method, static block, instance block, and constructor, as shown below?
public class First_C {  

      public void myMethod()   


    {  

    System.out.println("Method");  
    }  

      
    {  

    System.out.println(" Instance Block");  

    }  
          

    public void First_C()  


    {  

    System.out.println("Constructor ");  
    }  

    static {  

        System.out.println("static block");  
    }  

    public static void main(String[] args) {  


    First_C c = new First_C();  

    c.First_C();  
    c.myMethod();  

  }  
}   

a.
Instance block, method, static block, and constructor

b. Method, constructor, instance block, and static block

c. Static block, method, instance block, and constructor

d. Static block, instance block, constructor, and method


The correct answer is:


Static block, instance block, constructor, and method
Question 32
Correct

Mark 1.00 out of 1.00

Default (friendly) members of a super class are accessible to the subclass members, where both the classes are in different packages

Select one:
True

False 

The correct answer is 'False'.

Question 33
Correct

Mark 1.00 out of 1.00

The benefits of object-oriented modeling are which of the following?

a. All of the above 

b. Improved communication between users, analysts, etc. 

c. The ability to tackle more challenging problems 

d.
Reusability of analysis, design, and programming results 

The correct answer is: All of the above

Question 34
Correct

Mark 1.00 out of 1.00

An object of multi-level inherited abstract class can not be created in memory.

Select one:
True 

False

The correct answer is 'True'.


Question 35
Correct

Mark 1.00 out of 1.00

Can we return ‘this’ keyword from a method?

a. No

b. Yes 

The correct answer is:


Yes

◄ Pre-mid Semester Quiz Test

Jump to...

OFFLINE STUDENTS Pre-End Semester Examination ►


Dashboard /
Courses /
Autumn 2021-22 /
BTech Sem-3 /
CS 201 /
Pre-End Semester Examination

/
OFFLINE STUDENTS Pre-End Semester Examination

Started on Wednesday, 8 December 2021, 2:01 PM


State Finished
Completed on Wednesday, 8 December 2021, 2:59 PM
Time taken 57 mins 36 secs
Marks 34.00/55.00
Grade 9.27 out of 15.00 (62%)

Question 1
Incorrect

Mark 0.00 out of 1.00

Predict the output of the following Java program?

class Test 
{

  int i;

class Main 

{
   public static void main(String args[]) { 

     Test t; 
     System.out.println(t.i); 

a. Run time error

b. Garbage Value 

c. Compiler Error

d. 0

The correct answer is:


Compiler Error


Question 2
Correct

Mark 1.00 out of 1.00

When the same method call may at different times invoke different methods based on the dynamic type, this is called 

Answer: POLYMORPHISM 

The correct answer is: polymorphism

Question 3
Correct

Mark 1.00 out of 1.00

It is an error to have a method with the same signature in both the super class and its subclass

Select one:
True

False 

The correct answer is 'False'.

Question 4
Correct

Mark 1.00 out of 1.00

The ------------ type of variable can be accessed using classname.

Answer: STATIC 

The correct answer is: static


Question 5
Correct

Mark 1.00 out of 1.00

In an Interface

a. Some methods are abstract and some are concrete

b. All of its methods are abstract


c. There are no methods

d. Only one of its methods is abstract method

The correct answer is:


All of its methods are abstract

Question 6
Correct

Mark 1.00 out of 1.00

In multilevel inheritance, the last subclass inherits all methods and variables of

a. None of the above

b. The immediate Superclass


c. Few classes selected based on the Java compiler version

d. All classes above it

The correct answer is:


The immediate Superclass

Question 7
Correct

Mark 1.00 out of 1.00

Two methods cannot have the same name in Java.

Select one:
True

False 

The correct answer is 'False'.


Question 8
Correct

Mark 1.00 out of 1.00

start() method is used for which of the following

a. Execute the thread which is in 'ready to run' state

b. Invoke the thread, before the run method is executed.


c. Transit the thread from 'running' to 'ready to run' state

The correct answer is:


Invoke the thread, before the run method is executed.

Question 9
Correct

Mark 1.00 out of 1.00

All methods in an abstract class must be declared as abstract.

Select one:
True

False 

The correct answer is 'False'.

Question 10
Correct

Mark 1.00 out of 1.00

The programmer must explicitly create the System.in and System.out objects.

Select one:
True

False 

The correct answer is 'False'.


Question 11
Correct

Mark 1.00 out of 1.00

Select the method that should be overridden to provide thread's behaviour when Thread class is extended

a. yield

b. start

c. notify

d. run 

The correct answer is:


run

Question 12
Correct

Mark 1.00 out of 1.00

Consider the following two statements: 

(a) A publicly derived class is a subtype of its base class. 


(b) Inheritance provides for code reuse.

a. Neither of the statements (a) and (b) are correct

b. Both the statements (a) and (b) are correct. 

c. Statement (a) is correct and (b) is incorrect

d. Statement (a) is incorrect and (b) is correct

The correct answer is:

Both the statements (a) and (b) are correct.


Question 13
Correct

Mark 1.00 out of 1.00

When would you use a private constructor?

a. If you want to protect your class’s members from outside modification

b. When you get bored with public

c. If you want to disallow instantiation of that class from outside that class

d. Never, it's not allowed

The correct answer is:


If you want to disallow instantiation of that class from outside that class

Question 14
Incorrect

Mark 0.00 out of 1.00

Which of the following is true about interfaces in java.

1) An interface can contain the following type of members.

....public, static, final fields (i.e., constants) 

....default and static methods with bodies

2) An instance of the interface can be created.

3) A class can implement multiple interfaces.

4) Many classes can implement the same interface.

a. 1, 2, and 4 

b. 2, 3, and 4

c. 1, 2, 3, and 4

d. 1, 3, and 4

The correct answer is:

1, 3, and 4


Question 15
Incorrect

Mark 0.00 out of 1.00

What is the output of the following code,

class TestRunner {  


  static public int succeeded;

  static public int failed;


  

  public TestRunner() {    

  }
  

  public TestRunner(int s, int f) {


    succeeded=s; failed=f;

  }
  

  public void display() {


      System.out.println(succeeded + " " + failed);

  }

class check {

  public static void main(String[] args) {


    TestRunner tr = new TestRunner(1, 99);

    TestRunner.succeeded = 99;

    tr.display();
  }

a. 1   99

b. 99   0

c. 0   0 

d. 99   99

The correct answer is:


99   99


Question 16
Incorrect

Mark 0.00 out of 1.00

What will be the output of the following Java code?

class A
   {

       public int i;
       private int j;

   }   

   class B extends A
   {

       void display()
       {

           super.j = super.i + 1;
           System.out.println(super.i + " " + super.j);

       }
   }   

   class inheritance

  {
       public static void main(String args[])

       {
           B obj = new B();

           obj.i=1;
           obj.j=2;  

           obj.display();    

       }
  }

a. 2   2 

b. 3   3

c. Compilation Error

d. Runtime Error

The correct answer is:


Compilation Error


Question 17
Incorrect

Mark 0.00 out of 1.00

What would be the output of the following program?

abstract class demo


{

public int a;
demo()

a = 10;
}

abstract public void set();


abstract final public void get();

class Test extends demo


{

public void set(int a)

{
this.a = a;

final public void get()


{

System.out.println("a = " + a);


}

public static void main(String[] args)

{
Test obj = new Test();

obj.set(20);
obj.get();

}
}

a. a = 10 

b. NULL

c. Compilation Error

d. a = 20

The correct answer is:


Compilation Error


Question 18
Incorrect

Mark 0.00 out of 1.00

We can overload methods with differences only in their return type

Select one:
True 

False

The correct answer is 'False'.

Question 19
Incorrect

Mark 0.00 out of 1.00

The synchronized keyword is used to prevent Deadlock.

Select one:
True

False 

The correct answer is 'True'.

Question 20
Correct

Mark 1.00 out of 1.00

An object of multi-level inherited abstract class can not be created in memory.

Select one:
True 

False

The correct answer is 'True'.


Question 21
Correct

Mark 1.00 out of 1.00

How many instance initializers are in this code?

public class Bowling {


 { 

     System.out.println(); 

 }
 public Bowling () {

    System.out.println();
 }

 static { 
    System.out.println(); 

 }

 { 
     System.out.println(); 

 }
}

a. Three

b. None

c. One

d. Two 

The correct answer is:


Two


Question 22
Correct

Mark 1.00 out of 1.00

It is desired to design an object-oriented employee record system for a company. Each employee has a name, unique id and salary.
Employees belong to different categories and their salary is determined by their category. The functions to get Name, getld and
compute salary are required. Given the class hierarchy below, possible locations for these functions are;

i. getld is implemented in the superclass

ii. getld is implemented in the subclass


iii. getName is an abstract function in the superclass

iv. getName is implemented in the superclass


v. getName is implemented in the subclass

vi. getSalary is an abstract function in the superclass


vii. getSalary is implemented in the superclass

viii. getSalary is implemented in the subclass

CHOOSE THE BEST DESIGN AMONG THE FOLLOWING OPTIONS;

a. (i), (iv), (vi), (viii)


b. (i), (iii), (v), (vi), (viii)

c. (i), (iv), (vii)

d. (ii), (v), (viii)

The correct answer is:


(i), (iv), (vi), (viii)


Question 23
Correct

Mark 1.00 out of 1.00

Choose the correct line of code which should be used to start the Thread

a. Thread t = new Thread(X); t.start();

b. Thread t = new Thread(); x.run();

c. X run = new X(); Thread t = new Thread(run); t.start();


d. Thread t = new Thread(X);

The correct answer is:


X run = new X(); Thread t = new Thread(run); t.start();

Question 24
Incorrect

Mark 0.00 out of 1.00

A bookstore is working on an on-line ordering system. For each type of published material (books, movies, audio tapes) they need
to track the id, title, author(s), date published, and price. Which of the following would be the best design?

a. Create classes for each

b. Create classes Book, Movie, and AudioTape with the requested fields.

c. Create one class BookStore with the requested fields plus type.

d. Create one class PublishedMaterial with the requested fields plus type.

e. Create the class PublishedMaterial with children classes of Book, Movie, and AudioTape.

The correct answer is:


Create the class PublishedMaterial with children classes of Book, Movie, and AudioTape.


Question 25
Correct

Mark 1.00 out of 1.00

What will be the output of the following class?


class B 

{
   int b; 

   public B(int b) 


    { 

       b = b; 
     } 

   public static void main (String[] args) 

    { 
       B x = new B(10); 

     System.out.println("x.b :"+x.b);
   }

a. 0 

b. 0, 10

c. 10

d. 20

The correct answer is:


0


Question 26
Incorrect

Mark 0.00 out of 1.00

What is the output of this program,

class check {

public static void main(String[] args)


{

int x = 20;

System.out.println(x);
}

static
{

int x = 10;
System.out.print(x + " ");

}
}

a. 20    20

b. 10    20

c. 20   10

d. 10    10 

The correct answer is:


10    20

Question 27
Correct

Mark 1.00 out of 1.00

Abstract class support _____________ inheritance in Java.

a. Multiple Inheritance

b. Multilevel Inheritance

The correct answer is:


Multilevel Inheritance


Question 28
Correct

Mark 1.00 out of 1.00

Which is correct syntax for creating an object of Class in Java?

a. classname objectname= new() classname();

b. 
classname objectname= new classname();

c. classname objectname= new() integer;

d. classname objectname= new classname;

The correct answer is:


classname objectname= new classname();


Question 29
Incorrect

Mark 0.00 out of 1.00

What should be the execution order, if a class has a method, static block, instance block, and constructor, as shown below?
public class First_C {  

      public void myMethod()   


    {  

    System.out.println("Method");  
    }  

      
    {  

    System.out.println(" Instance Block");  

    }  
          

    public void First_C()  


    {  

    System.out.println("Constructor ");  
    }  

    static {  

        System.out.println("static block");  
    }  

    public static void main(String[] args) {  


    First_C c = new First_C();  

    c.First_C();  
    c.myMethod();  

  }  
}   

a. Method, constructor, instance block, and static block

b. Instance block, method, static block, and constructor 

c. Static block, method, instance block, and constructor

d. Static block, instance block, constructor, and method

The correct answer is:


Static block, instance block, constructor, and method


Question 30
Correct

Mark 1.00 out of 1.00

What best describes the purpose of a class’s constructor?

a. Names the new object

b. Initialize the fields in the object.


c. Determines the amount of space needed for an object and creates the object.

d. None of the above

The correct answer is:


Initialize the fields in the object.

Question 31
Correct

Mark 1.00 out of 1.00

A synchronized method can be used by

a. Multiple threads concurrently

b. One Thread at a time 

The correct answer is:


One Thread at a time

Question 32
Correct

Mark 1.00 out of 1.00

Which of the following is a Deadlock condition in Java?

a. A situation where a thread is waiting to acquire an object lock that another thread holds, and this second thread is waiting for an 
object lock that the first thread holds.

b. A situation where a low priority thread waiting to acquire an I/O resource but other high priority threads never relinquish the
resources.

c. A situation where two threads waiting to get terminated.

d. A situation where two threads are executing concurrently and requesting for separate resources.

The correct answer is:


A situation where a thread is waiting to acquire an object lock that another thread holds, and this second thread is waiting for an object lock
that the first thread holds.


Question 33
Incorrect

Mark 0.00 out of 1.00

The methods wait() and notify() are defined in

a. java.lang.String

b. java.lang.Runnable

c. java.lang.Object

d. java.lang.Thread 

The correct answer is:


java.lang.Object

Question 34
Incorrect

Mark 0.00 out of 1.00

What type of relationship is presented in the following program

a. an 'is-a' relationship 

b. both

c. a 'has-a' relationship

d. Niether

The correct answer is:


a 'has-a' relationship


Question 35
Incorrect

Mark 0.00 out of 1.00

A subclass can --------------- a superclass method by declaring a method with the same signature as the superclass method.

Answer: ACCESS 

The correct answer is: Override


Question 36
Incorrect

Mark 0.00 out of 1.00

What should be the correct output of the following program,

a. Hi
hello

world

b. hello 

world

c. Hi hello

Hi world

d. Hi 

Hi

The correct answer is:


Hi 

Hi

Question 37
Incorrect

Mark 0.00 out of 1.00

The keyword used to call methods in the superclass is ----------- .

Answer: SUPER 

The correct answer is: super

Question 38
Correct

Mark 1.00 out of 1.00

Protected members of a super class are accessible to the subclass members, where both the classes are in the same package.

Select one:
True 

False

The correct answer is 'True'.


Question 39
Incorrect

Mark 0.00 out of 1.00

What would be the output of the following Java program:

class one1
{

one1()
{

System.out.println("Hello");
}

}
class two2 extends one1

public class check {

public static void main(String[] args)


{

two2 t = new two2();

a. Hello Hello 

b. Blank. No output.

c. Compiler Error. 

d. Hello

The correct answer is:


Hello


Question 40
Incorrect

Mark 0.00 out of 1.00

Abstraction and encapsulation are fundamental principles that underlie the object-oriented approach to software development. What can
you say about the following two statements;

I. Abstraction allows us to focus on what something does without considering the complexities of how it works.
II. Encapsulation allows us to consider complex ideas while ignoring irrelevant details that would confuse us.

a.
Neither I nor II is correct.

b. Only I is correct.

c. Only II is correct.

d. Both I and II are correct.

The correct answer is:

Neither I nor II is correct.

Question 41
Correct

Mark 1.00 out of 1.00

How many Threads can a Process have?

a. Multiple 

b. Equal to the number of classes

c. 1

d. Equal to the number of methods

The correct answer is:


Multiple


Question 42
Correct

Mark 1.00 out of 1.00

How many arguments are required in the definition of an overloaded unary operator?

a. None 

b. 2

c. 3

d. 1

The correct answer is:


None

Question 43
Incorrect

Mark 0.00 out of 1.00

The ............ type of variable must be initialized while declaring.

Answer: DATA 

The correct answer is: final

Question 44
Correct

Mark 1.00 out of 1.00

Operator overloading is

a. Giving C++ operators more operands than usual

b. Making C++ operators work with objects

c. Giving new meanings to existing C++ operators



d. Making new C++ operators

The correct answers are:


Making C++ operators work with objects,

Giving new meanings to existing C++ operators


Question 45
Correct

Mark 1.00 out of 1.00

Given that Student is a class, how many reference variables and objects are created by the following code?
Student studentName, studentId;  

studentName = new Student();  


Student stud_class = new Student(); 

a. Three reference variables and two objects are created.



b. Three reference variables and three objects are created.

c. Two reference variables and two objects are created.

d. One reference variable and two objects are created.

The correct answer is:


Three reference variables and two objects are created.

Question 46
Correct

Mark 1.00 out of 1.00

An individual array element that is passed to a method and modified in that method will contain the modified value when the called method
completes execution

Select one:
True

False 

The correct answer is 'False'.


Question 47
Correct

Mark 1.00 out of 1.00

yield() methods causes which of the following

a. Terminates a 'running'' thread

b. Currently running thread is moved from 'running' to 'read to run' state 

c. Currently 'ready to run' thread to 'running' thread

d. None of the above

The correct answer is:


Currently running thread is moved from 'running' to 'read to run' state

Question 48
Incorrect

Mark 0.00 out of 1.00

Which of the following is TRUE about Interfaces in Java,

1) An interface can contain the following type of members.

....public, static, final fields (i.e., constants) 


....default and static methods with bodies

2) An instance of the interface can be created.

3) A class can implement multiple interfaces.

4) Many classes can implement the same interface.

a. 1, 2, and 4 

b. 1, 2, 3, and 4

c. 1, 3, and 4

d. 2, 3, and 4

The correct answer is:


1, 3, and 4


Question 49
Correct

Mark 1.00 out of 1.00

When we implement the Runnable interface, we must define the method

a. start()

b. runnable()

c. init()

d. run() 

The correct answer is:


run()


Question 50
Incorrect

Mark 0.00 out of 1.00

Predict the output of the following program.


abstract class demo

{
public int a;

demo()
{

a = 10;
}

abstract public void set();

abstract final public void get();

class Test extends demo

public void set(int a)


{

this.a = a;
}

final public void get()

{
System.out.println("a = " + a);

public static void main(String[] args)

Test obj = new Test();


obj.set(20);

obj.get();
}

a. a=10 

b. a=10; a=20;

c. Compilation Error

d. a=20

The correct answer is:


Compilation Error 
Question 51
Correct

Mark 1.00 out of 1.00

Which of the following is True for Threads

a. Threads doesn't have own stack.

b. Threads have their own heap allocated area.

c. Threads have their own stack.


d. None of the above

The correct answer is:


Threads have their own stack.

Question 52
Correct

Mark 1.00 out of 1.00

-------------- keyword allows us to define one class as an extension of another.

Answer: EXTENDS 

The correct answer is: extends

Question 53
Correct

Mark 1.00 out of 1.00

It is an error if a class with one or more abstract methods is not explicitly declared as abstract.

Select one:
True 

False

The correct answer is 'True'.


Question 54
Incorrect

Mark 0.00 out of 1.00

Which of the following is FALSE about abstract classes in Java

a. A class can be made abstract without any abstract method 

b. A class can inherit from multiple abstract classes.

c.  Abstract classes can have constructors

d.
 If we derive an abstract class and do not implement all the abstract methods, then the derived class should also be marked as
abstract using ‘abstract’ keyword

The correct answer is:


A class can inherit from multiple abstract classes.

Question 55

Correct

Mark 1.00 out of 1.00

The benefits of object-oriented modeling are which of the following?

a. Reusability of analysis, design, and programming results 

b.
The ability to tackle more challenging problems 

c. All of the above 

d.
Improved communication between users, analysts, etc. 

The correct answer is: All of the above

◄ Mid Semester Online Examination

Jump to...

ONLINE STUDENTS Pre-End Semester Examination ►

You might also like