(a) State the difference between == operator and equals() method.

ICSE Class 10 Computer Applications PYQ · 2016 Paper · Section A

21 Mark · 2016 · Section A · 2016 Paper

(a) State the difference between == operator and equals() method.

Show SolutionHide Solution↓
equals()==
It is a methodIt is a relational operator
It is used to check if the contents of two strings are same or notIt is used to check if two variables refer to the same object in memory
Example:
String s1 = new String("hello");
String s2 = new String("hello");
boolean res = s1.equals(s2);
System.out.println(res);
The output of this code snippet is true as contents of s1 and s2 are the same.
Example:
String s1 = new String("hello");
String s2 = new String("hello");
boolean res = s1 == s2;
System.out.println(res);
The output of this code snippet is false as s1 and s2 point to different String objects.

(b) What are the types of casting shown by the following examples:

  1. char c = (char) 120;
  2. int x = ‘t’;
  1. Explicit Cast.
  2. Implicit Cast.

(c) Differentiate between formal parameter and actual parameter.

Formal parameterActual parameter
Formal parameters appear in function definition.Actual parameters appear in function call statement.
They represent the values received by the called function.They represent the values passed to the called function.

(d) Write a function prototype of the following:
A function PosChar which takes a string argument and a character argument and returns an integer value.

int PosChar(String s, char ch)

(e) Name any two types of access specifiers.

  1. public
  2. private
← Previous questionNext question →

Browse the free Computer Applications sample bank