C#, Java, and C++ Programming Concepts
Test your knowledge of C# serialization and delegates, Java inheritance and generics, and C++ pointers and structs
Questions
I have a function declaration like this(in C/C++).const int f(int* a){ ..... // Do something here return *a; }what is the purpose of the keyword const here?
- It is just a fancy keyword, No purpose here
- Prevents the compiler from assigning the function as an rvalue
- Prevents the compiler from assigning the function as an lvalue
- It makes sure that the return value is a const and is not changed by anyone else
A friend of mine once wrote a function as follows. int * func() { int i; for (int k=0;k<200;k++) //Do something here .... return &i; } I think it is faulty . What is wrong here?
- Nothing is wrong. You are wrong.
- Loops are not allowed inside the function scope, Since it degrades performance
- My friend tried to return a pointer to a local function variable , which is invalid once the function call compltes.
- The value i is not properly initialised, SO it may contain some garbage .
I want to declare a pointer to a constant int variable ,pointing to a constant memory location. What is the syntax?
- const int* ptr
- const* int ptr
- There is no such declaration like that
- const int* const ptr
void vp; char c; int i=20; float f=30.00; pick the line which will cause an error in a C++ compiler
- vp=&f;
- c=(char*)&i;
- c=vp;
- *i++;
- f++;
consider the following line in the c++ code extern "C" { f1(); f2();... } The purpose of the extern keyword is
- They tell the C++ compiler that they are functions compiled by a C compiler , So that they can be used in C++
- they mean that the function are declared somewhere and defined somewhere
- They improve performance
- They are used with extern variables.
A ( hypothetical ;) ) graphics program uses the following structure to represet a 3d point struct point3d { int x; int y; int z; // X,y,z represent the three cooddinates of a 3d point in space }; A function was written to calculate the distace between two point3d objects. void func(point3d pt1,point3d pt2) { // Calculate the distance ..... } say at run time 2 million point3d struct objects were created and the above mentioned function was called say 1 million times. Calling the above mentioned function will result in a performance hit because
- The point3d is represented as struct . change it to a class and it will run better
- The point3d struct is not byte aligned.
- The in the function point3d struct parameters are passed by value, Which will cause additional overhead.
- The point3d struct has 3 members of type int . Change it to short ,the program will run faster.
public static void main(String[] args){ Integer i = new Integer(5); List myList; myList = new ArrayList(); myList.add(3); myList.add(5); myList.add(7); myList.remove(i); for(String s: myList) { System.out.println("List Value >> "+s); } } What is the output?
- 3,7
- 3,5,7
- index Outofbound exception
- Compilation fails
public static void main(String[] args){ Integer i = new Integer(5); List myList; myList = new ArrayList(); myList.add(3); myList.add(5); myList.add(7); myList.remove(i); for(String s: myList) { System.out.println("List Value >> "+s); } } What is the output?
- 3,7
- 3,5,7
- index Outofbound exception
- Compilation fails
class A{ public void _a(){ System.out.println("A"); } } class B extends A{ public void _a(){ System.out.println("B"); } } public class InheritanceTest { public static void main(String[] args){ A aa = new B(); System.out.println(aa._a()); } } What is the output?
- B
- A
- Compilation fails
- none of these
class B1{ public B1(){ System.out.println("B"); } } class A1 extends B1{ void A1(){ System.out.println("A"); } } public class Test { public static void main(String[] args){ B1 a = new A1(); } } what will be output?
- A
- B
- BA
- AB
class A2{ static void doprint(){ System.out.println("A2"); } } class B2 extends A2{ static void doprint(){ System.out.println("B2"); } } public class StaticTest { public static void main(String[] args) { A2 a = new B2(); a.doprint(); } }
- A2
- B2
- Compilation fails
- runtime error
public class SwitchTest { public static void main(String[] args) { Boolean b = Boolean.TRUE; switch(b) { case(true): System.out.println("A"); case(false): System.out.println("B"); case(3): System.out.println("C"); } } } output?
- A
- ABC
- comilation fails
- AB
Which one of the following is not a JSP Action?
- jsp:forward
- jsp:getBean
- jsp:param
- jsp:getProperty
- Which of the following can be used/efficient to store items(name/value pairs) in which the number of items can be less or more(not known)?
- Hashtable.
- ListDictionary.
- Hybrid Dictionary
- ArrayList.
- StringDictionary.
Which of the following can be used to store items(name/value pairs) implemented as strongly typed strings?
- Hashtable.
- ListDictionary.
- Hybrid Dictionary.
- NameValueCollection.
- StringDictionary.
Valuetypes cannot be assigned with NULL Value?
- TRUE.
- FALSE
- Cant say.
- Depends on the valuetype used.
Constants cannot be marked with which of the below keywords
- Public.
- Private.
- Protected.
- static.
- Internal.
- ProtectedInternal.
A delegate is
- A method without code
- A method which is called when an event is triggered.
- A method which doesnot contain code.
- A reference to a method which itself doesnot contain code.
which of the following classes require the Serializable attribute to be defined to serialize and deserialize objects?
- BinaryFormatter and SOAPFormatter
- BinaryFormatter and XmlSerializer
- XmlSerializer.
- BinaryFormatter , SOAP Formatter, XmlSerializer
IDeserializationCallback.OnDeserialization() , an interface method implemented is called automatically by runtime
- After serialization is complete
- Before deserialization
- After Deserialization is complete
- To be called explicitly after serialization
- To be called explicitly after Deserialization.