2022 11 28 X ICSE Computer Solution - PMD
2022 11 28 X ICSE Computer Solution - PMD
com
(c) An instance method can only be invoked bound to an object of the class.
For example : player2.displayperformance ( );
The object player2 on which the instance method displayperformance( ) operates is
called implicit argument. The object variable bound to which an instance method is
invoked, is its implicit argument.
(d) Call by value: In call by value mechanism, a copy of Actual parameters are passed
to the Formal parameters. Hence any changes made in the Formal parameter’s do
not reflecton the Actual parameters. Thus, Actual parameters remain unchanged.
Here, variables are used as Actual and Formal arguments.
Call by reference: In this mechanism, the Actual and Formal paremeters both
represent the same memory location, since here objects are used as Actual and
Formal arguments (in Java). Henceforth changes made in Formal parameters get
reflected in the Actual parameters too.
(f) A destructor is a method which is executed when the object is removed from
computer’s memory.
Sample(~)// a destructor with same name as that of its class followed by a tilde~
(g) The default constructor provided by the compiler initializes all instances variables to
their default values. It initialises integers to 0, floating point numbers to 0.0, boolean
values to false and objects to null.
2. (a) (c) (b) (a) (c) (d) (d) (d) (e) (d)
(f) (c) (g) (d) (h) (c) (i) (b) (j) (a)
(k) (b) (l) (a) (m) (d) (n) (a) (o) (a)
(p) (b) (q) (b) (r) (a) (s) (a) (t) (c)
3. import java.util.*;
class Anagrams
{
int c = 0;
void input()throws Exception
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a word : ");
String s = sc.next();
System.out.println("The Anagrams are : ");
display("",s);
System.out.println("Total Number of Anagrams = "+c);
}
void display(String s1, String s2)
{
if(s2.length()<=1)
{
c++;
System.out.println(s1+s2);
}
else
{
for(int i=0; i<s2.length(); i++)
{
String x = s2.substring(i, i+1);
String y = s2.substring(0, i);
String z = s2.substring(i+1);
display(s1+x, y+z);
} } }
public static void main(String args[])throws Exception
{ Anagrams ob=new Anagrams();
ob.input(); } }
} } }
6. import java.util.*;
class sortParagraph
{
// Function to count no. of words in every sentence
int countWords(String s)
{
StringTokenizer str = new StringTokenizer(s," .,?!");
int c = str.countTokens();
return c;
}
// Function to sort the sentences in ascending order of their no. of words
void sort(String w[], int p[])
{
{ int n = w.length;
for(int i=0; i<n; i++)
{ System.out.println(w[i]+"\t=\t"+p[i]); } }