You are on page 1of 4

Q1

A class is a user defined blueprint or prototype from which objects are created.  It
represents the set of properties or methods that are common to all objects of one type.

Furthermore, a class can be defined as a template/blueprint that describes the


behavior/state that the object of its type support.

Q2

A class can be defined in three (03) ways:

1. A class can be defined using the class keyword and the name of the class:

class MyClassName {

...

2. A class can also be defined using the extend keyword if this class is a subclass of another
class to indicate the superclass of this class:

class myClassName extends mySuperClassName {

...

3. Lastly a class can be defined using the implement key word if this class implements a
specific interface:

class MyRunnableClassName implements Runnable {

...

Q3.

A Java method is a collection of statements that are grouped together to perform an operation.
When you call the System.out.println() method, for example, the system actually executes
several statements in order to display a message on the console

Thus, a method is a set of code which is referred to by name and can be called or invoked at any
point in a program simply by utilizing the method's name.

Q4.
The basic method definition looks like:

returntype methodname (type1 arg1, type2 arg2, type3 arg3..) {

... body of the method

Thus, Method definitions have four basic parts:

• The name of the method

• The type of object this method returns

• A list of parameters

• The body of the method

By and large, the method’s nature is a combination of the name of the method, the type of object
this method returns, and a list of parameters

For code illustration confer a program named myClass in the java quiz project..

Q5

i) Implement is a java keyword used to implement an interface. An interface is an


abstract "class" that is used to group related methods with "empty" bodies:
Thus, to access the interface methods, the interface must be "implemented" by
another class with the implements keyword. The body of the interface method is
provided by the "implement" class:
ii) Extend is a Java Keyword, which is used in inheritance process of java. It is a
keyword that indicates the parent class that a subclass is inheriting.
By and large, the extends keyword extends a class indicating that a subclass is
inherited from a parent class thus, making it possible for a subclass to inherit
attributes and methods from a parent class.

Q6

A variable is a container that holds values that are used in a Java program.

Therefore, Variables which are defined without the STATIC keyword and are Outside any
method declaration are Object-specific and are known as instance variables.

Thus, Instance variables are variables declared in a class, but outside a method, constructor or
any block.

Q7
A constant is a variable whose value cannot change once it has been assigned. Java doesn't have
built-in support for constants, but the Constant variable are created using static and final
modifiers.

Q8

Class variables also known as static variables are declared with the static keyword in a class, but
outside a method, constructor or a block.

Q9

A return statement causes the program control to transfer back to the caller of a method. Every
method in Java is declared with a return type and it is mandatory for all java methods. A return
type may be a primitive type like int, float, double, a reference type or void type(returns
nothing).

Q10

Confer the program named simple.java from the java quiz project.

Q11

THIS Keyword is a reference variable in Java that refers to the current object.

The various usages of 'THIS' keyword in Java are as follows:

It can be used to refer instance variable of current class

It can be used to invoke or initiate current class constructor

It can be passed as an argument in the method call

It can be passed as argument in the constructor call

It can be used to return the current class instance

For code illustration confer the program named thisMethod.java from the java quiz project.

Q12

Method overloading is a principle that allows different methods to have the same name, but
different signatures where the signature can differ by the number of input parameters or type of
input parameters or both.
Q 13

For code illustration confer the program named Methodoverload.java from the java quiz project.

Q14

Overriding is a feature that allows a subclass or child class to provide a specific implementation
of a method that is already provided by one of its super-classes or parent classes. When a method
in a subclass has the same name, same parameters or signature and same return type(or sub-type)
as a method in its super-class, then the method in the subclass is said to override the method in
the super-class.

Q15

For code illustration confer the overriding project from the java quiz folder.

Q16.

A constructor initializes an object when it is created. It has the same name as its class and
is syntactically similar to a method. However, constructors have no explicit return type.

For code illustration confer the program named ConsMain.java from the java quiz project.

You might also like