Please briefly define the following concepts, keywords, and terms, as they perta
ID: 3686228 • Letter: P
Question
Please briefly define the following concepts, keywords, and terms, as they pertain to the Java language. Use examples where appropriate.
Java Runtime Environment (JRE)
null pointer assignment
object
private
privilege
public
scope
subclass
subtype
superclass
void
while
abstract class
array index out of bounds
boolean
break
class
class method
constructor
do
else
inheritance
Java Development Kit (JDK)
Java Runtime Environment (JRE)
null pointer assignment
object
private
privilege
public
scope
subclass
subtype
superclass
void
while
Explanation / Answer
A.
Abstract:
___________
Abstract is a keyword in Java language.
Abstraction is a process of hiding the implementation details from the user, only functionality will be provided to the user.
Abstract class:
________________
A class is declared abstract keyword,is known as abstract class in java.It can have abstract and non -abstract methods(method without body).
Example for Abstract class:
abstract class Bike
{
abstract void run();
}
class Honda4 extends Bike
{
void run()
{
System.out.println("running safely..");
}
public static void main(String args[])
{
Bike obj = new Honda4();
obj.run();
}
}
Array index out of bound:
_________________________
Array index out of bounds is a run time exception in java.
The index of an array is an integer value that resides in the interval [0, n-1], where n is the size of the matrix. If we request for an index that is either negative, or greater than or equal to the size of the array, an ArrayIndexOutOfBoundsException is thrown in Java.
Boolean:
______________
Boolean is a keyword in java.
It has returns two values either true or false.
Boolean Example in java:
public class JavaBooleanExample
{
public static void main(String[] args)
{
boolean b1 = true;
boolean b2 = false;
boolean b3 = (10 > 2)? true:false;
System.out.println("Value of boolean variable b1 is :" + b1);
System.out.println("Value of boolean variable b2 is :" + b2);
System.out.println("Value of boolean variable b3 is :" + b3);
}
}
Break:
__________-
Break is a statement in java.
when break statemnet is encounteed inside a loop, the loop is immediately terminated and program control resumes at the text statement following the loop.
Break example :
class Main
{
public static void main(String args[])
{
for(int var =0; var < 5 ; var++)
{
System.out.println(“Var is : “ + var);
if(var == 3)
break;
}
}
}
Class:
_________
A class is a group of objects that has common properties. It is a template or blueprint from which objects are created. A class in java can contain: data member. method.
Class method:
_______________
A method is a set of code which is referred to by name and can be called (invoked) at any point in a program simply by utilizing the method's name. Think of a method as a subprogram that acts on data and often returns a value. Each method has its own name.
Constructor:
_________________
Constructor in java is a special type of method that is used to initialize the object. Java constructor is invoked at the time of object creation. It constructs the values i.e. provides data for the object that is why it is known as constructor.
Constructor example:
class Programming
{
Programming() //constructor method
{
System.out.println("Constructor method called.");
}
public static void main(String[] args)
{
Programming object = new Programming(); //creating object
}
}
Inheritance:
______________
Inheritance in java is a mechanism in which one object acquires all the properties and behaviors of parent object. The idea behind inheritance in java is that you can create new classes that are built upon existing classes.
Inheritance example:
class Superclass
{
int age;
Superclass(int age)
{
this.age = age;
}
public void getAge()
{
System.out.println("The value of the variable named age in super class is: " +age);
}
}
public class Subclass extends Superclass
{
Subclass(int age)
{
super(age);
}
public static void main(String argd[])
{
Subclass s = new Subclass(24);
s.getAge();
}
}
Object:
___________-
Object which defines its properties and behaviors. Java class objects exhibit the properties and behaviors defined by its class. A class can contain fields and methods to describe the behavior of an object.