Java Programming Fundamentals
Test your knowledge of Java programming basics including data types, operators, inheritance, keywords, and control flow statements.
Questions
Can constructors be declared static?
- True
- False
Are static methods allowed to access instance variables using "this"
- No
- Yes
- Can be in special cases
- None
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 }}
- Compile error at 2,3,4,5
- Compile error at 1,2,3,4,5
- prints 3
- none of the above
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?
- Prints one, two , three
- prints one
- compile time error
- Run time Exception
Which of these below are java key words?
- new
- break
- default
- goto
select which of these are correct
- int = 32-bit signed
- float = 32-bit IEEE 754 floating point
- long = 64-bit signed
- short = 18-bit signed
A top level class can be marked as
- public
- synchronise
- private
- transient
" ?: " is a
- Conditional operator
- assignment operator
- bitwise operator
- none
Which of the following are bit wise operators in java?
- ~
- <<
- >>
- &&
The expression to the switch must be of a type
- byte/int,
- short,
- char,
- float
All classes extend from
- java.lang.object
- java.lang
- none
- java.lang.string
abstract keyword is used
- When a class is not to be instantiated,
- declare a method without providing the implementation
- cannot use a field declared abstract
- none
Which is not a part of java
- final
- finally
- finalize
- finalised
Using super keywork how many levels up we can go
- one level
- two levels
- multiple levels
- none
Can a private method of a super class be declared in a sub class?
- yes
- no
- cannot say
- none
assuming all the variables are declared and initialied properly , will the below line compile? for (i=3,j=76;i>589;j++,i++){}
- Yes will compile
- no doesnot compile
- changes have to be made in checking the variables
- none
Using the "Super" keyword we can go one level up (T/F)
- True
- False
" ?: " is a conditional Operator (T/F)
- True
- False
Can final method be overridden?
- True
- False
Can you automatically convert long value into int , if the long value is small enough to fit into an int.
- True
- False