Java Programming Fundamentals

Test your knowledge of Java programming basics including data types, operators, inheritance, keywords, and control flow statements.

20 Questions Published

Questions

Question 1 True/False

Can constructors be declared static?

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

Are static methods allowed to access instance variables using "this"

  1. No
  2. Yes
  3. Can be in special cases
  4. None
Question 3 Multiple Choice (Single Answer)

class C{ int i; public static void main (String[] args) { int i; //1 private int a = 1; //2 protected int b = 1; //3 public int c = 1; //4 System.out.println(a+b+c); //5 }}

  1. Compile error at 2,3,4,5
  2. Compile error at 1,2,3,4,5
  3. prints 3
  4. none of the above
Question 4 Multiple Choice (Single Answer)

class C { public static void main(String[] args) { int i1=1; switch(i1){ case 1: System.out.println("one"); case 2: System.out.println("two"); case 3: System.out.println("three"); }}} What is the result of attempting to compile and run the program?

  1. Prints one, two , three
  2. prints one
  3. compile time error
  4. Run time Exception
Question 5 Multiple Choice (Multiple Answers)

Which of these below are java key words?

  1. new
  2. break
  3. default
  4. goto
Question 6 Multiple Choice (Multiple Answers)

select which of these are correct

  1. int = 32-bit signed
  2. float = 32-bit IEEE 754 floating point
  3. long = 64-bit signed
  4. short = 18-bit signed
Question 7 Multiple Choice (Multiple Answers)

A top level class can be marked as

  1. public
  2. synchronise
  3. private
  4. transient
Question 8 Multiple Choice (Multiple Answers)

" ?: " is a

  1. Conditional operator
  2. assignment operator
  3. bitwise operator
  4. none
Question 9 Multiple Choice (Multiple Answers)

Which of the following are bit wise operators in java?

  1. ~
  2. <<
  3. >>
  4. &&
Question 10 Multiple Choice (Multiple Answers)

The expression to the switch must be of a type

  1. byte/int,
  2. short,
  3. char,
  4. float
Question 11 Multiple Choice (Single Answer)

All classes extend from

  1. java.lang.object
  2. java.lang
  3. none
  4. java.lang.string
Question 12 Multiple Choice (Multiple Answers)

abstract keyword is used

  1. When a class is not to be instantiated,
  2. declare a method without providing the implementation
  3. cannot use a field declared abstract
  4. none
Question 13 Multiple Choice (Multiple Answers)

Which is not a part of java

  1. final
  2. finally
  3. finalize
  4. finalised
Question 14 Multiple Choice (Multiple Answers)

Using super keywork how many levels up we can go

  1. one level
  2. two levels
  3. multiple levels
  4. none
Question 15 Multiple Choice (Multiple Answers)

Can a private method of a super class be declared in a sub class?

  1. yes
  2. no
  3. cannot say
  4. none
Question 16 Multiple Choice (Multiple Answers)

assuming all the variables are declared and initialied properly , will the below line compile? for (i=3,j=76;i>589;j++,i++){}

  1. Yes will compile
  2. no doesnot compile
  3. changes have to be made in checking the variables
  4. none
Question 17 True/False

Using the "Super" keyword we can go one level up (T/F)

  1. True
  2. False
Question 18 True/False

" ?: " is a conditional Operator (T/F)

  1. True
  2. False
Question 19 True/False

Can final method be overridden?

  1. True
  2. False
Question 20 True/False

Can you automatically convert long value into int , if the long value is small enough to fit into an int.

  1. True
  2. False