Java Programming Fundamentals
Test your knowledge of Java programming fundamentals including control structures, memory management, exception handling, and object-oriented programming concepts.
Questions
Consider the following piece of code: 1 long i = 2 ; 2 switch (i) { 3 case 1: 4 System.out.println ("Case 1"); 5 case 2: 6 System.out.println ("Case 2"); 7 case 3: 8 System.out.println ("Case 3"); 9 default: 10 System.out.println ("Default"); 11 } Which of the following lines will be included in the output? (Choose all that apply, please bear with code as formating it sems is not possible,first numbers represent line numbers)
- Case 1
- Case 2
- Case 3
- Default
- Compiler Error
In Java the compiler will always insert a default , no argument constructor into any class definition
- True
- False
In a method call when an object reference is passed as an argument , So what gets passed actually ?
- The object itself
- a copy of reference
- the original reference
- a reference to a copy
In Java if an arithmetic operation is performed then , In case the operands are of different types the resulting type is always the widest of two types
- True
- False
consider the following scenarioint i = 0;if ( i ) {System.out.println("This won't print");}else{System.out.println("This prints");}
- This won't print
- This prints
- There's a runtime exception
- scenario is not legal
A constructor can be declared abstract
- True
- False
The legal values for a boolean in java are choose all that applies
- 1,0
- TRUE,FALSE
- true , false , TRUE,FALSE
- true , false
Its possible for a non-abstract class to have abstract methods.
- True
- False
The following statement would allocate memory on? char *ptr = malloc(10);
- Stack
- Heap
- Code Segment
- Data Segment
In the following code variable test would be created on? static int test;
- Heap
- Stack
- Code Segment
- Data Segment
In the following code variable test1 would be allocated memory on?int func(){int test1 = 10;return test1;}void main(){ int i = 0; i = func();}
- Heap
- Stack
- Code Segment
- Data Segment
In the following segments which is the read only segment?
- Heap
- Stack
- Code Segment
- Data Segment
Can we change the content of string letral?
- True
- False
Can a constructor be declared as private?
- True
- False
The access modifier of an overloaded method is different. Is this valid?
- True
- False
The following code is compiled: double abc = 100.0; double xyz = abc/0; What is the result?
- Compilation Error
- Arithmetic Exception
- Compiles with no errors
- None of the above
Consider the following case: A return statement is there in the catch block. An exception occurs and is caught. Now will the finally block be executed?
- will execute
- will not execute
- Compilation Error
- Runtime Exception
Overloaded methods should not throw new checked exceptions that have not been thrown by the original method?
- True
- False
Consider the following case: A = false B = true; What is the result of A && B ?
- True
- False
Consider the following case; int i; int k; for(i=0;k<10;i++){/* The body */} This will not compile?
- True
- False