

MCQOPTIONS
Saved Bookmarks
This section includes 1698 Mcqs, each offering curated multiple-choice questions to sharpen your General Awareness knowledge and support exam preparation. Choose a topic below to get started.
701. |
Which is valid in a class that extends class A? class A { protected int method1(int a, int b) { return 0; } } |
A. | Public int method1(int a, int b) {return 0; } |
B. | Private int method1(int a, int b) { return 0; } |
C. | Public short method1(int a, int b) { return 0; } |
D. | Static protected int method1(int a, int b) { return 0; } |
Answer» B. Private int method1(int a, int b) { return 0; } | |
702. |
What is the output of this program? Note: Host URL is written in html and simple text. import java.net.*; class networking { public static void main(String[] args) throws Exception { URL obj = new URL("https://www.mcqsmentor.com/"); URLConnection obj1 = obj.openConnection(); System.out.print(obj1.getContentType()); } } |
A. | Html |
B. | Text |
C. | Html/text |
D. | Text/html |
Answer» E. | |
703. |
What is the output of this program? Note: Host URL is having length of content 127. import java.net.*; class networking { public static void main(String[] args) throws Exception { URL obj = new URL("https://www.mcqsmentor.com/"); URLConnection obj1 = obj.openConnection(); int len = obj1.getContentLength(); System.out.print(len); } } |
A. | 126 |
B. | 127 |
C. | Compilation Error |
D. | Runtime Error |
Answer» C. Compilation Error | |
704. |
What is the output of this program? Note: Host URL was last modified on july 18 tuesday 2013 . import java.net.*; class networking { public static void main(String[] args) throws Exception { URL obj = new URL("https://www.mcqsmentor.com/"); URLConnection obj1 = obj.openConnection(); System.out.print(obj1.getLastModified); } } |
A. | July |
B. | 18-6-2013 |
C. | Tue 18 Jun 2013 |
D. | Tue Jun 18 2013 |
Answer» E. | |
705. |
What is the output of this program? import java.io.*; class Chararrayinput { public static void main(String[] args) { String obj = "abcdefgh"; int length = obj.length(); char c[] = new char[length]; obj.getChars(0, length, c, 0); CharArrayReader input1 = new CharArrayReader(c); CharArrayReader input2 = new CharArrayReader(c, 1, 4); int i; int j; try { while ((i = input1.read()) == (j = input2.read())) { System.out.print((char)i); } } catch (IOException e) { e.printStackTrace(); } } } |
A. | Abc |
B. | Abcd |
C. | Abcde |
D. | None of the mentioned |
Answer» E. | |
706. |
Which two of the following are legal declarations for nonnested classes and interfaces? 1. final abstract class Test {} 2. public static interface Test {} 3. final public class Test {} 4. protected abstract class Test {} 5. protected interface Test {} 6. abstract public class Test {} |
A. | 1 and 4 |
B. | 2 and 5 |
C. | 3 and 6 |
D. | 4 and 6 |
Answer» D. 4 and 6 | |
707. |
What is the output of this program? Note: Execution command line: $ java exception_handling one two class exception_handling { public static void main(String args[]) { try { int a = args.length; int b = 10 / a; System.out.print(a); try { if (a == 1) a = a / a - a; if (a == 2) { int c = {1}; c[8] = 9; } } catch (ArrayIndexOutOfBoundException e) { System.out.println("TypeA"); } catch (ArithmeticException e) { System.out.println("TypeB"); } } } |
A. | TypeA |
B. | TypeB |
C. | 0TypeA |
D. | 0TypeB |
Answer» E. | |
708. |
What is the output of this program? class Output { public static void main(String args[]) { double x = 3.14; int y = (int) Math.ceil(x); System.out.print(y); } } |
A. | 0 |
B. | 3 |
C. | 3.0 |
D. | 4 |
Answer» E. | |
709. |
What is the output of this program? |
A. | Runtime Error |
Answer» B. | |
710. |
What will be the output of the program? Note: The command line invocation is > java X a b public class X { public static void main(String [] args) { String names [] = new String[5]; for (int x=0; x < args.length; x++) names[x] = args[x]; System.out.println(names[2]); } } |
A. | Names |
B. | Null |
C. | Compilation fails |
D. | An exception is thrown at runtime |
Answer» C. Compilation fails | |
711. |
The HTML element is a A. Inline element B. Outline element C. Block level element D. None Answer: C . Block level element 0Shares0 0 |
A. | Inline element |
B. | Outline element |
C. | Block level element |
D. | None |
Answer» D. None | |
712. |
Which class uses hierarchical inheritance in following code? class A { int a; }; class B:class A { int b; }; class C:class A,class B { int c; }; class D:class A { int d; }; |
A. | Class A,B,C |
B. | Class B,C,D |
C. | Class A,C,D |
D. | Class D,A,B |
Answer» E. | |
713. |
Which among the following is correct for following code ? abstract class A { public Int a; public void disp(); }; class B:public A { public: void dis() { court<<a; } }; class C:private A { public void incr() { a++; } } void main() { B b.disp(); } |
A. | Compile time error |
B. | Runtime error |
C. | Program runs and o/p is 0 |
D. | Program runs and o/p is garbage value |
Answer» B. Runtime error | |
714. |
Which method in the code below is single level inherited? class A { protected int a, b; public: void show() { cout<<a<<b; } }; class B: public A { public: void disp() { cout<<a++<<b++; } }; class C: private A, public B { void avg() { cout<<(a+b)/2; } }; |
A. | Class A |
B. | Class B |
C. | Class C |
D. | None |
Answer» C. Class C | |
715. |
Output of following program? class A { protected: int a,b; public: void disp() { cout<<a<<b; } }; class B:public A { int x,y; }; |
A. | Garbage value |
B. | Compile time error |
C. | Runtime error |
D. | Runs but gives random values as output |
Answer» C. Runtime error | |
716. |
Which type of inheritance is illustrated by the following code? class student{ public: int marks; }; class topper: public student { public: char grade; }; class average{ public: int makrs_needed; }; class section: public average{ public: char name[10]; }; class overall: public average{ public: int students; }; |
A. | Single level |
B. | Multilevel and single level |
C. | Hierarchical |
D. | Hierarchical and single level |
Answer» D. Hierarchical and single level | |
717. |
Which among the following is correct for the following code? class A { public : class B { public : B(int i): data(i) { } int data; } }; class C: public A { class D:public A::B{ }; }; |
A. | Multi-level inheritance is used, with nested classes |
B. | Multiple inheritance is used, with nested classes |
C. | Single level inheritance is used, with enclosing classes |
D. | Single level inheritance is used, with both enclosing and nested classes |
Answer» E. | |
718. |
Which members can t be accessed in derived class in multiple inheritance ? |
A. | Private members of base |
B. | Public members of base |
C. | Protected members of base |
D. | All the members of base |
Answer» B. Public members of base | |
719. |
Does following code show multiple inheritance? class A { int a; }; class B { int b; }; class C:public A, public B { int c; }; class D:public C { int d; }; |
A. | Yes, class C and class D |
B. | Yes, All together it s multilevel |
C. | No, 4 classes are used |
D. | No, multiple inheritance is used with class A, B and C |
Answer» E. | |
720. |
What will be the output of the following code? import java.awt.Point; class Testing { public static void main(String[] args) { Point t1,t2,t3; t1=new Point(100,100); t2=t1; t3=t1; t1.x=200; t1.y=200; t2.x=300; t3.y=500; System.out.println( Point 1: + p1.x + , + p1.y); } } |
A. | Point 1: 200, 200 |
B. | Point 1: 100,100 |
C. | Point 1: 300, 300 |
D. | Point 1: 300, 500 |
Answer» E. | |
721. |
What will be the output of the following code? Class A { int i; public : A(int n) { i=n; cout<< inside constructor ; } ~A() { cout<< destroying <<i; } void seti(int n) { i=n; } int geti() { return I; } }; void t(A ob) { cout<< something ; } int main() { A a(1); t(a); cout<< this is i in main ; cout<<a.geti(); } |
A. | Inside constructor something destroying 2this is i in main destroying 1 |
B. | Inside constructor something this is i in main destroying 1 |
C. | Inside constructor something destroying 2this is i in main |
D. | Something destroying 2this is i in main destroying 1 |
Answer» B. Inside constructor something this is i in main destroying 1 | |
722. |
The object can t be: |
A. | Passed by reference |
B. | Passed by value |
C. | Passed by copy |
D. | Passed as function |
Answer» E. | |
723. |
What is size of the object of following class (64 bit system)?class student { int rollno; char name[20]; static int studentno; }; |
A. | 20 |
B. | 22 |
C. | 24 |
D. | 28 |
Answer» D. 28 | |
724. |
Which feature of OOP is indicated by the following code? class student{ int marks; }; class topper:public student{ int age; topper(int age){ this.age=age; } }; |
A. | Inheritance |
B. | Polymorphism |
C. | Inheritance and polymorphism |
D. | Encapsulation and Inheritance |
Answer» E. | |
725. |
Which class/set of classes can illustrate polymorphism in the following code: abstract class student { public : int marks; calc_grade(); } class topper:public student { public : calc_grade() { return 10; } }; class average:public student { public : calc_grade() { return 20; } }; class failed{ int marks; }; |
A. | Only class student can show polymorphism |
B. | Only class student and topper together can show polymorphism |
C. | All class student, topper and average together can show polymorphism |
D. | Class failed should also inherit class student for this code to work for polymorphism |
Answer» D. Class failed should also inherit class student for this code to work for polymorphism | |
726. |
Which among following is correct for initializing the class below? class student{ int marks; int cgpa; public: student(int i, int j){ marks=I; cgpa=j } }; |
A. | Student s[3]={ s(394, 9); s(394, 9); s(394,9), }; |
B. | Student s[2]={ s(394,9); s(222,5) }; |
C. | Student s[2]={ s1(392,9); s2(222,5) }; |
D. | Student s[2]={ s[392,9]; s2[222,5] }; |
Answer» C. Student s[2]={ s1(392,9); s2(222,5) }; | |
727. |
What is default access specifier for data members or member functions declared within a class without any specifier, in C++ ? class Student { int a; public : float a; }; |
A. | Private |
B. | Protected |
C. | Public |
D. | Depends on compiler |
Answer» B. Protected | |
728. |
What is output of the following program? class student { public : int marks; void disp() { cout< |
A. | Its base classIts derived class |
B. | Its base class Its derived class |
C. | Its derived classIts base class |
D. | Its derived class Its base class |
Answer» B. Its base class Its derived class | |
729. |
Find the output of the program: class education { char name[10]; public : disp() { cout< |
A. | Its school education system |
B. | Its education system |
C. | Its school education systemIts education system |
D. | Its education systemIts school education system |
Answer» B. Its education system | |
730. |
Consider the following code and select the correct option: class student { int marks; public : int* fun() { return &marks; } }; main() { student s; int *ptr=c.fun(); return 0; } |
A. | This code is good to go |
B. | This code may result in undesirable conditions |
C. | This code will generate error |
D. | This code violates encapsulation |
Answer» E. | |
731. |
Consider the following code snippet: var f = new java.io.File( /tmp/test ); var out = new java.io.FileWriter(f); out instanceof java.io.Reader What will be the output for the above code snippet? |
A. | Error |
B. | True |
C. | Exception |
D. | False |
Answer» E. | |
732. |
Consider the following code snippet: const pi=3.14; var pi=4; console.log(pi); What will be the output for the above code snippet? |
A. | This will flash an error |
B. | Prints 4 |
C. | Prints 3.14 |
D. | Ambiguity |
Answer» B. Prints 4 | |
733. |
Consider the following code snippet. What would be the output if oddsums(5); is executed afted the below code snippet ? namespace McqsMentorConsoleApplication function oddsums(n) { let total = 0, result=[]; for(let x = 1; x <= n; x++) { let odd = 2*x-1; total += odd; result.push(total); } return result; } |
A. | Returns [1,4,9,16,25] |
B. | Returns [1,2,3,4,5] |
C. | Returns [3,6,9,12,15] |
D. | Returns [1,3,5,7,9] |
Answer» B. Returns [1,2,3,4,5] | |
734. |
Consider the following code snippet: console.log(p) If p is not defined, what would be the result or type of error? |
A. | Zero |
B. | Null |
C. | ReferenceError |
D. | ValueNotFoundError |
Answer» D. ValueNotFoundError | |
735. |
Consider the following code snippet: let x=x+1; console.log(x); What will be the result for the above code snippet? |
A. | 0 |
B. | Null |
C. | ReferenceError |
D. | NaN |
Answer» E. | |
736. |
Consider the following code snippet: [x,y]=[y,x]; What is the result of the above code snippet? |
A. | Throws exception |
B. | Swap the value of the two variables |
C. | Flashes an error |
D. | Creates a new reference object |
Answer» D. Creates a new reference object | |
737. |
Consider the following code snippet: let succ = function(x) x+1, yes = function() true, no = function() false; What convenience does the above code snippet provide? |
A. | Functional behaviour |
B. | Modular behaviour |
C. | No convenience |
D. | Shorthand expression |
Answer» B. Modular behaviour | |
738. |
Consider the following code snippet: data.sort(function(a,b),b-a); What does the above code do? |
A. | Sort in the alphabetical order |
B. | Sort in the chronological order |
C. | Sort in reverse alphabetical order |
D. | Sort in reverse numerical order |
Answer» E. | |
739. |
The $ present in the RegExp object is called a |
A. | Character |
B. | Matcher |
C. | Metacharacter |
D. | Metadata |
Answer» D. Metadata | |
740. |
Consider the following statement containing regular expressions var text = testing: 1, 2, 3 ; var pattern = /d+/g; In order to check if the pattern matches, the statement is |
A. | Text==pattern |
B. | Text.equals(pattern) |
C. | Text.test(pattern) |
D. | Pattern.test(text) |
Answer» E. | |
741. |
Consider the following statement var Set = sets.Set; var s = new Set(1,2,3); What could be the efficiency quotient of the above two statements ? |
A. | The programmer imports at once the frequently used values into the global namespace |
B. | There is no efficiency quotient, the programmer tries to make it inefficient |
C. | The programmer needs to import the Sets everytime he wants to use it |
D. | All of the mentioned |
Answer» B. There is no efficiency quotient, the programmer tries to make it inefficient | |
742. |
Consider the following code snippet var sets = com.davidflanagan.collections.sets; What is the programmer trying to do in the above code snippet? |
A. | Importing a single module |
B. | Importing a module partially |
C. | Importing a namespace |
D. | Importing the entire module |
Answer» E. | |
743. |
Consider the code snippet given below: var count = [1,,3]; What is the observation made? |
A. | The omitted value takes "undefined" |
B. | This results in an error |
C. | This results in an exception |
D. | None of the mentioned |
Answer» B. This results in an error | |
744. |
Consider the following code snippet. The result would be namespace McqsMentorConsoleApplication var a1 = [,,,]; var a2 = new Array(3); 0 in a1 0 in a2 |
A. | True false |
B. | False true |
C. | True true |
D. | False true |
Answer» B. False true | |
745. |
Consider the following code snippet : if (!a[i]) continue ; What is the observation made ? |
A. | Skips the undefined elements |
B. | Skips the non existent elements |
C. | Skips the null elements |
D. | All of the mentioned |
Answer» E. | |
746. |
Consider the following code snippet : var a = [1,2,3,4,5]; a.slice(0,3); What is the possible output for the above code snippet ? |
A. | Returns [1,2,3] |
B. | Returns [4,5] |
C. | Returns [1,2,3,4] |
D. | Returns [1,2,3,4,5] |
Answer» B. Returns [4,5] | |
747. |
Consider the following code snippet. The final output for the shift() is namespace McqsMentorConsoleApplication var a = []; a.unshift(1); a.unshift(22); a.shift(); a.unshift(3,[4,5]); a.shift(); a.shift(); a.shift(); |
A. | 1 |
B. | [4,5] |
C. | [3,4,5] |
D. | Exception is thrown |
Answer» B. [4,5] | |
748. |
Consider the following code snippet. What will the code snippet result ? namespace McqsMentorConsoleApplication function printprops(o) { for(var p in o) console.log(p + ": " + o[p] + "n"); } |
A. | Prints the contents of each property of o |
B. | Returns undefined |
C. | All of the mentioned |
D. | None of the mentioned |
Answer» C. All of the mentioned | |
749. |
Consider the following code snippet. What is the function of the code snippet? namespace McqsMentorConsoleApplication var scope = "global scope"; function checkscope() { var scope = "local scope"; function f() { return scope; } return f; |
A. | Returns value null |
B. | Returns exception |
C. | Returns the value in scope |
D. | None of the mentioned |
Answer» D. None of the mentioned | |
750. |
Consider the following code snippet. What does the below code result? namespace McqsMentorConsoleApplication function hypotenuse(a, b) { function square(x) { return x*x; } return Math.sqrt(square(a) + square(b)); } |
A. | Sum of square of a and b |
B. | Square of sum of a and b |
C. | Sum of a and b square |
D. | None of the mentioned |
Answer» B. Square of sum of a and b | |