Programming 3B Test Memo PDF
Programming 3B Test Memo PDF
SUBJECT Programming 3B
SUBJECT CODE PRG320
TEST/EXAM Test Memo
SEMESTER 2nd
DATE WRITTEN 14 September 2021
NUMBER OF PAGES 11
TOTAL MARKS 100
DURATION 2 HOURS
PASS MARK 50%
WEIGHTING 20%
EXAMINER Thandanani Dube
REQUIREMENTS:
Learner Requirements:
Equipment Requirement:
Question 1: [20]
A. Functional parameter
B. Class parameter
C. Optional parameter
D. Object pass
1.3 A _________in a method header receives a copy of the value passed to it.
A. Value parameter
B. Optional parameter
C. Field parameter
D. Object parameter
A. URl parameter
B. Reference parameter
A. Reference parameter
B. Output parameter
C. Input parameter
D. Method call
1.6 A _______is a local array declared within a method header that can accept
any number of elements of the same data type.
A. Object parameter
B. File path parameter
C. Input parameter
D. Parameter array
1.7 An out _________ is a variable declared at the point where it is passed to a method as
an out argument.
A. Class
B. Object
C. Method
D. variable
1.8 ___________involves the ability to write multiple versions of a method using the same
method name but different parameter lists.
A. Overloading
B. Overriding
C. Overlapping
D. Class extends
A. Path
B. signature
C. Identifier
D. Object
1.10 __________is the process of determining which of multiple applicable methods is the
best match for a method call.
A. Overload resolution
B. Method control
C. Method override
D. Underline resolution
2.1 The TryParse () methods are an alternative to the Convert () and Parse ().
True
2.2 A parameter array is a local array declared within the method header by using the
keyword
Array [ ]
False, A parameter array is a local array declared within the method header by using the
keyword
params.
2.3 When you overload a C# method, you write multiple methods with Multiple names.
False, When you overload a C# method, you write multiple methods with a shared name.
2.4 The TryParse () method requires the receiving variable to be an out parameter for two
reasons: The argument does not have an assigned value in the calling method. The
method returns a Boolean value that indicates whether the conversion was successful
and, so, it cannot return the score value too.
True
2.5 Methods are required to carry out tasks in an application. The Method describes the
mechanisms that perform its task. In a class, you provide one or two methods designed to
perform the class’s tasks.
True
1. Objects: are reference types, and are created on the heap, using the keyword new.
2. Access modifier: determines which class methods -- including methods of other classes
--can see and use a member variable or method within a class.
3. Internal: The members in class A that are marked internal are accessible to methods of
any class in A’s assembly.
4. Private: the members in class A that are marked private are accessible only to methods
of class A
5. Protected internal: the members in class A that are marked protected internal are
accessible to methods of class A, to methods of classes derived from class A and also to
any class in A’s assembly. This is effectively protected or internal ( there is no concept of
protected and internal )
There are 10 errors in this demonstration fix them to allow the program to function.
using System;
using System.Collections. Generic;
using System.Linq;
using System.Text;
// create a GradeBook objects and call its DisplayMessage Method
public class GradeBookTest
{
public static void Main (String [] args)
{
HET: DIPLOMA IN INFORMATION
TECHNOLOGY
Module: Programming 3B Page 8 of 11 2021
//create a GradeBook objects and assign it to myGradeBook
GradeBook myGradeBook = new GradeBook ();
//call myGradeBook's Method
myGradeBook.DisplayMessage();
Console.Read();
}
}
using System;
// create a GradeBook objects and call its DisplayMessage Method
public class GradeBookTest
{
public static void Main(String [] args)
{
//create a GradeBook objects and assign it to myGradeBook
GradeBook myGradeBook = new GradeBook ();
//Prompt for an input Coursename
Console.WriteLine("Please enter the course name:");
string nameofcource = Console.ReadLine(); //read the line of text and store
Console.WriteLine(); //output a blank space
//call myGradeBook's Method
//and pass the nameofcourse as an argument
myGradeBook.DisplayMessage(nameofcource);
Console.Read();
}
}
In C#, you create a derived class by adding a colon after the name of the derived
class, followed by the name of the base class:
public class ListBox : Window
Create a code that declares a new class, ListBox, that derives from Window. You can
read the colon as "derives from."
using System;
using System.Collections.Generic; using System.Linq; using System.Text;
using System.Threading.Tasks;
namespace Values
{
public class Window
{
// constructor takes two integers to
// fix location on the console
public Window(int top, int left)
{
this.top = top;
this.left = left;
}
// simulates drawing the window public void DrawWindow()
{
Console.WriteLine("Drawing Window at {0} , {1} ", top, left);
}
// these members are private and thus invisible // to derived class methods; we'll
examine this // later in the chapter private int top;
private int left;
// ListBox derives from Window
}
public class ListBox : Window{
HET: DIPLOMA IN INFORMATION
TECHNOLOGY
Module: Programming 3B Page 10 of 11 2021
// constructor adds a parameter
public ListBox(int top,int left, string theContents): base(top, left){ mListBoxContents
= theContents;
}
// a new version (note keyword) because in the
// derived method we change the behavior public new void DrawWindow( ){
base.DrawWindow( ); // invoke the base method
Console .WriteLine ("Writing string to the listbox: {0} ", mListBoxContents);
}
private string mListBoxContents;
}
public class Tester{
public static void Main( ) { // create a base instance
Window w = new Window(5,10); w.DrawWindow( );
// create a derived instance
ListBox lb = new ListBox(20,30,"Hello world"); lb.DrawWindow( );
}
}
}