Author:
Daisy Williams
Oct
28
The package statement is used to declare packages. The word package is a keyword in Java. This statement is not technically needed to write a complete Java program. However, if it appears, it must be the first executable statement in the program. Only comments or white spaces are allowed before a package statement. There can be only one package declaration in a program. If no package declaration appears, the class will belong to the default package.
For example, the following source code file defines a class named ClassA in the package named package4:
package package4;
Author:
Daisy Williams
Sep
1
The this keyword refers to the currently executing instance of a class. It is commonly used to access members from within constructors, instance methods, and instance accessors. However, the static member functions do not have a this pointer. For example:
using System;
public class Students
{
public string name;
public string subcode;
//Constructor.
public Students(string name, string subcode)
{
//Use of this keyword to qualify members hidden by similar names.
this.name = name;
this.subcode = subcode;
}
}
The this keyword is used to pass an object as a parameter to other methods. For example:
Cal_Marks(this);
Permanent link to this post (97 words, estimated 23 secs reading time)
Author:
Daisy Williams
Aug
29
The instanceof operator is a binary operator that determines at runtime whether its left operand is an instance of its right operand.
Syntax:
obj instanceof type
where, obj (the left operand) must be an instance of a class and type (the right operand) may be a class, interface, or an array type. The instanceof operator evaluates to true if the left operand is of the specified type or can be cast to the specified type. Otherwise, it evaluates to false. The instanceof operator cannot be used with primitive data types.