MFC and Java Programming Quiz
Test your knowledge of MFC (Microsoft Foundation Classes) for Windows C++ programming and core Java programming concepts including strings, inheritance, threading, and operators.
Questions
byte b; final int a = 10; final int x = a; b = x; System.out.println("The value of b is " + b);
- Compilation error
- Runtime Error
- 10
- None of these
Which one is not correct A. x = = Float.NaN B. Float.isNan(x); C. Myobject .equals(float.NaN);
- A
- B
- Both
- None of these
What will happen when you attempt to compile and run the following code? (Assume that the code is compiled and run with assertions enabled.) public class AssertTest { public void methodA(int i) { assert i >= 0 : methodB(); System.out.println(i); } public void methodB() { System.out.println("The value must not be negative"); } public static void main(String args[]) { AssertTest test = new AssertTest(); test.methodA(-10); } }
- It will print -10
- It will result in Assertion Error showing the message -"The value must not be negative".
- The code will not compile.
- None of these.
What will happen when you attempt to compile and run the following code? interface MyInterface { } public class MyInstanceTest implements MyInterface { static String s; public static void main(String args[]) { MyInstanceTest t = new MyInstanceTest(); if(t instanceof MyInterface) { System.out.println("I am true interface"); } else { System.out.println("I am false interface"); } if(s instanceof String) { System.out.println("I am true String"); } else { System.out.println("I am false String"); } } }
- Prints : "I am false interface" followed by " I am false String"
- Prints : "I am true interface" followed by " I am true String"
- Prints : "I am true interface" followed by " I am false String"
- Compile-time error
What results from attempting to compile and run the following code? public class Ternary { public static void main(String args[]) { int a = 5; System.out.println("Value is - " + ((a < 5) ? 9.9 : 9)); } }
- prints: Value is - 9
- prints: Value is - 5
- Compilation error
- None of these
What will happen when you attempt to compile and run the following code? class MyThread extends Thread { public void run() { System.out.println("MyThread: run()"); } public void start() { System.out.println("MyThread: start()"); } } class MyRunnable implements Runnable { public void run() { System.out.println("MyRunnable: run()"); } public void start() { System.out.println("MyRunnable: start()"); } } public class MyTest { public static void main(String args[]) { MyThread myThread = new MyThread(); MyRunnable myRunnable = new MyRunnable(); Thread thread = new Thread(myRunnable); myThread.start(); thread.start(); } }
- Prints : MyThread: start() followed by MyRunnable:run()
- Prints : MyThread: run() followed by MyRunnable:start()
- Prints : MyThread: start() followed by MyRunnable:start()
- Compile time error
What will happen when you attempt to compile and run the following code? public class Static { static { int x = 5; } static int x,y; public static void main(String args[]) { x--; myMethod(); System.out.println(x + y + ++x); } public static void myMethod() { y = x++ + ++x; } }
- Compile-time error
- prints : 3
- prints : 1
- prints : 7
Given the following code, what will be the output? class Value { public int i = 15; } public class Test { public static void main(String argv[]) { Test t = new Test(); t.first(); } public void first() { int i = 5; Value v = new Value(); v.i = 25; second(v, i); System.out.println(v.i); } public void second(Value v, int i) { i = 0; v.i = 20; Value val = new Value(); v = val; System.out.println(v.i + " " + i); } }
- 15 0 20
- 15 0 15
- 20 0 20
- 0 15 20
What will happen when you attempt to compile and run the following code? class MyParent { int x, y; MyParent(int x, int y) { this.x = x; this.y = y; } public int addMe(int x, int y) { return this.x + x + y + this.y; } public int addMe(MyParent myPar) { return addMe(myPar.x, myPar.y); } } class MyChild extends MyParent { int z; MyChild (int x, int y, int z) { super(x,y); this.z = z; } public int addMe(int x, int y, int z) { return this.x + x + this.y + y + this.z + z; } public int addMe(MyChild myChi) { return addMe(myChi.x, myChi.y, myChi.z); } public int addMe(int x, int y) { return this.x + x + this.y + y; } } public class MySomeOne { public static void main(String args[]) { MyChild myChi = new MyChild(10, 20, 30); MyParent myPar = new MyParent(10, 20); int x = myChi.addMe(10, 20, 30); int y = myChi.addMe(myChi); int z = myPar.addMe(myPar); System.out.println(x + y + z); } }
- 300
- 240
- 120
- Compilation error
What will be the result of executing the following code? 1. boolean a = true; 2. boolean b = false; 3. boolean c = true; 4. if (a == true) 5. if (b == true) 6. if (c == true) System.out.println("Some things are true in this world"); 7. else System.out.println("Nothing is true in this world!"); 8. else if (a && (b = c)) System.out.println("It's too confusing to tell what is true and what is false"); 9. else System.out.println("Hey this won't compile");
- The code won't compile
- "Some things are true in this world" will be printed
- "Hey this won't compile" will be printed
- None of these
What will be the result of executing the following code? // Filename; SuperclassX.java package packageX; public class SuperclassX { protected void superclassMethodX() { } int superclassVarX; } // Filename SubclassY.java 1. package packageX.packageY; 2. 3. public class SubclassY extends SuperclassX 4. { 5. SuperclassX objX = new SubclassY(); 6. SubclassY objY = new SubclassY(); 7. void subclassMethodY() 8. { 9. objY.superclassMethodX(); 10. int i; 11. i = objY.superclassVarX; 12. } 13. }
- Compilation error at line 5
- Compilation error at line 9
- Runtime exception at line 11
- None of these
What is displayed when the following code is compiled and executed? String s1 = new String("Test"); String s2 = new String("Test"); if (s1==s2) System.out.println("Same"); if (s1.equals(s2)) System.out.println("Equals");
- Same
- Equals
- The code compiles, but nothing is displayed upon execution.
- The code fails to compile
What will be output of this program? String str="TCS"; str.concat("Bangalore");
- TCS
- Bangalore
- TCS Bangalore
- Syntax Error
which class provides member functions for device-context operations, working with drawing tools, type-safe graphics device interface (GDI) object selection, and working with colors and palettes?
- CDOCItem
- CDC
- CBrush
- CAnimateCtrl
A ____________is a collection that associates a key object with a value object.
- Array
- List
- Map
- Vector
Useful Features of CObject classes are
- serialization support
- platform independent
- object diagnostic output
- run-time class information
The MFC library implements a Windows menu, from the Win32’s HMENU class, through the CMenu class
- True
- False
An application built on the framework can have multiple objects of a class derived from CWinApp.
- True
- False
The CPropertyPage class is declared in which header file?
- afxdlg.h header file.
- afxdlgs.h header file
- afxprp.h header file
- afxproppg.h header file
The framework uses ____________ to connect messages and commands to their handler functions.
- MapHandler
- CommandMaps
- HandleCommands
- Message maps