Java and Python Programming Fundamentals Quiz

Test your knowledge of Java and Python programming concepts including OOP, collections, string manipulation, operators, and language-specific behaviors.

20 Questions Published

Questions

Question 1 Multiple Choice (Single Answer)

By using which method ,How can one increase size of an ArrayList?

  1. incSize(int minCapacity)
  2. ensureCapacity(int minCapacity)
  3. incCapicity(int minCapacity)
  4. All of the Above
Question 2 Multiple Choice (Single Answer)

what a Clone method returns in ArrayList?

  1. Returns String
  2. Returns an Array
  3. Returns a shallow copy of this ArrayList instance
  4. Returns Void
Question 3 True/False

Is Abstract Class is Parent Class of ArrayList?

  1. True
  2. False
Question 4 True/False

Python lists are mutable

  1. True
  2. False
Question 5 Multiple Choice (Single Answer)

name=[1]*3

  1. [11]
  2. syntax error
  3. [1,1,1]
  4. runtime error
Question 6 Multiple Choice (Single Answer)

a=['a','b'] x=[a,'y']

  1. x[0][0]
  2. Syntax error at line 1
  3. Syntax error at line 2
  4. runtime error
Question 7 Multiple Choice (Single Answer)

x=[1,2,3,4,5] print x[-1]

  1. error
  2. 5
  3. garbage number
  4. 3
Question 8 Multiple Choice (Single Answer)

x=[1,2,3,4,5] x[3:3]='sagar' print x

  1. error
  2. [1,2,3,4,'sagar',5]
  3. [1,2,3,'sagar']
  4. none
Question 9 Multiple Choice (Single Answer)

If you run the code below, what gets printed out? String s=new String("Bicycle"); int iBegin=1; char iEnd=3; System.out.println(s.substring(iBegin,iEnd));

  1. Bic
  2. ic
  3. icy
  4. error: no method matching substring(int,char)
Question 10 Multiple Choice (Single Answer)

What does the following paint( ) method draw?

  1. A circle at (100, 100) with radius of 44
  2. A circle at (100, 44) with radius of 100
  3. A circle at (100, 44) with radius of 44
  4. The code does not compile
Question 11 Multiple Choice (Multiple Answers)

Which of the following statements are true

  1. When you construct an instance of File, if you do not use the filenaming semantics of the local machine, the constructor will throw an IOException.
  2. When you construct an instance of File, if the corresponding file does not exist on the local file system, one will be created.
  3. When an instance of File is garbage collected, the corresponding file on the local file system is deleted.
  4. None of the above.
Question 12 Multiple Choice (Multiple Answers)

Which of these are not legal identifiers. Select all the correct answers.

  1. 1alpha
  2. _abcd
  3. xy+abc
  4. transient
  5. account-num
  6. very_long_name
Question 13 Multiple Choice (Single Answer)

What gets printed on the standard output when the class below is compiled and executed. Select the one correct answer. public static ShortCkt { public static void main(String args[]) { int i = 0; boolean t = true; boolean f = false, b; b = (t && ((i++) == 0)); b = (f && ((i+=2) > 0)); System.out.println(i); } }

  1. 0
  2. 1
  3. 2
  4. 3
Question 14 True/False

Is it possible to have a virtual destructor?

  1. True
  2. False
Question 15 Multiple Choice (Single Answer)

interface my_interface{ public void show(); } public class test08 { public static void main(String[] args) { my_interface mi = new B(); mi.show(); } } class A implements my_interface{ public void show(){ System.out.println("This is implemented method "); } } class B extends A{ public void show(){ System.out.println("This is overrided method "); } } What is the output

  1. This is implemented method
  2. This is overrided method
  3. Compile time Error
  4. Run time error
Question 16 Multiple Choice (Multiple Answers)

By default any class would be supplied with?

  1. Constructor
  2. Destructor
  3. Overloaded assignment operator
  4. Default Copy Constructor
Question 17 Multiple Choice (Single Answer)

public class Change { public static void main(String args[]) { System.out.println(2.00 - 1.10); } } What is the output

  1. 0.9
  2. 0.90
  3. It varies
  4. None of the above
Question 18 Multiple Choice (Single Answer)

public class test08 { public static void main(String[] args) { final int start = Integer.MAX_VALUE - 100; final int end = Integer.MAX_VALUE; int count = 0; for (int i = start; i <= end; i++) count++; System.out.println(count); } } What will be the output

  1. 100
  2. 101
  3. 102
  4. None of the above
Question 19 Multiple Choice (Single Answer)

class A{ public void show(){ System.out.println("This is A"); } class B extends A{ protected void show(){ System.out.println("This is B"); } public class Main{ public static void main(String[] args) { A a = new B(); a.show(); } } What is the output

  1. This is A
  2. This is B
  3. Nothing will be printed as output
  4. None of the above
Question 20 Multiple Choice (Single Answer)

public class test08 { public static void main(String[] args) { System.out.print("H" + "a"); System.out.print('H' + 'a'); } } What is the output?

  1. HaHa
  2. Ha
  3. Compile error
  4. None of the above