You are on page 1of 5

Internal Assessment 1

2 Mark
1. What do you mean by Bytecode?
Java bytecode is the result of the compilation of a Java program, an intermediate
representation of that program which is machine independent. 
The Java bytecode gets processed by the Java virtual machine (JVM) instead of the
processor.

2. Define abstraction and encapsulation.


Abstraction is a process of hiding the implementation details and showing only
functionality to the user. For example: phone call, we don't know the internal processing.
In java, we use abstract class and interface to achieve abstraction.
Encapsulation in java is a process of wrapping code and data together into a single unit,
for example capsule i.e. mixed of several medicines. A java class is the example of
encapsulation.

3. What is meant by public static void main(String args[]) in java?


 public keyword is an access modifier which represents visibility, it means it is visible to
all.
 static is a keyword, if we declare any method as static, it is known as static method. The
core advantage of static method is that there is no need to create object to invoke the
static method. The main method is executed by the JVM, so it doesn't require to create
object to invoke the main method. So it saves memory.
 void is the return type of the method, it means it doesn't return any value.
 main represents startup of the program.
 String[] args is used for command line argument.

4. What is array? How to declare array and how to allocate the memory to for array?
a. Array is a collection of similar type of elements that have contiguous memory
location.
b. It is a data structure and store only fixed set of elements in a java array.
c. Array in java is index based, first element of the array is stored at 0 index
Declaration:
1. int mark[]; mark=new int[20];
2. int mark[]=new int[20];
3. int mark[]={10,20,30};
Where new is a special type operator that can be used to allocate memory for any array variable
5. Summarize any four Java doc comments.
Javadoc is a tool which comes with JDK and it is used for generating Java code
documentation in HTML format from Java source code, which requires documentation in
a predefined format.
6. What is a package?
A java package is a group of similar types of classes, interfaces and sub-packages.
Package in java can be categorized in two form, built-in package and user-defined
package.
Advantage of Java Package
1) Java package is used to categorize the classes and interfaces so that they can be
easilymaintained.
2) Java package provides accessprotection.
3) Java package removes namingcollision.

7. Define Class hierarchy. Give an example


The class hierarchy defines the inheritance relationship between the classes.  The root of
the class hierarchy is the class Object.  Every class in Java directly or indirectly extends
(inherits from) this class. 

8. Differentiate method overriding with method overloading. Give Example.


No Method Overloading Method Overriding
.
1) Method overloading is used to Method overriding is used to provide the
increase the readability of the specific implementation of the method that
program. is already provided by its super class.
2) Method overloading is Method overriding occurs in two classes
performed within class. that have IS-A (inheritance) relationship.
3) In case of method In case of method overriding, parameter
overloading, parameter must be must be same.
different.
4) Method overloading is the example Method overriding is the example of run
of compile time polymorphism. time polymorphism.

9. What is dynamic binding?


When type of the object is determined at run-time, it is known as dynamic binding.
Example
class Animal
{
void eat()
{
System.out.println("animal is eating...");
}
}
class Dog extends Animal
{
void eat()
{
System.out.println("dog is eating...");
}

public static void main(String args[])


{
Animal a=new Dog();
a.eat();
}
}

10. Give the use of super keyword.


1. super() invokes the constructor of the parent class.
2. super.variable_name refers to the variable in the parent class.
3. super.method_name refers to the method of the parent class

11. Differentiate this and super usage with example.


super() as well as this() both are used to make constructor calls.
super() is used to call Base class’s constructor(i.e, Parent’s class) while this() is used to
call current class’s constructor.
class A
{
int i;
}
class B extends A
{ int b;
B(int a, int b)
{
super.i = a; // assigns value to base class variable
this.b = b; // points to current object.
}

12. Define objects and classes in Java.


A class is a template for an object, and an object is an instance of a class. A class is declared by use of the
class keyword.
class Box
{
double width;
doubleheight;
double depth;
}
Box mybox = new Box(); // create a Box object called mybox
myboxwill be an instance of Box.

13. Define access specifier.


These Specifiers determine whether a field or method in a class, can be used or invoked by
another method in another class or sub-class
Types Of Access Specifiers :
In java we have four Access Specifiers and they are listed below.
1. public – accessible everywhere
2. private – accessible only within class
3. protected – accessible within package and outside the package but through inheritance(sub class) only
4. default(no specifier)- accessible only withinpackage

14. Can a java source file be saved using name other than the class name?
Yes,it is possible to compile a java source file with different file name but you need to make sure none of
the classes defined inside are public...when you compile the source file the corresponding .class files for the
classes inside the source file are created.

15. Illustrate constructor in java./What is a constructor? What are the rules for defining a constructor?

 Constructors are special member functions whose task is to initialize the objects of itsclass.
 It is a special member function; it has the same as the classname.
 Java constructors are invoked when their objects are created. It is named such because, it
constructs the value, that is provides data for the object and are used to initializeobjects.
class Box {
double width; double height; double depth;
Box() // Default Constructor
{
width=height=depth=10;
}
Box(double i,doublej,double k)// Parameterized Constructor
{
width=i;
height=j;
depth=k;
}
}

16. Infer how to import a single package.


 Importing single member of a package, use import packagename.classname
 only declared class of this package will be accessible.
Example //save by A.java
package pack;
public class A
{ public void msg()
{System.out.println("Hello");} }
//save by B.java
packagemypack;
importpack.A;
class B{
public static void main(String args[]){
A obj = new A();
obj.msg(); } }

17. Define Java virtual machine (JVM).


JVM (Java Virtual Machine) is an abstract machine. It is a specification that provides runtime environment
in which java bytecode can beexecuted.
JVMs are available for many hardware and software platforms (i.e. JVM is platformdependent).
The JVM performs followingoperation:
 Loads code
 Verifies code
 Executes code
 Provides runtime environment

18. Define static method.


 A static method belongs to the class rather than object of a class.
 A static method can be invoked without the need for creating an instance of a class.
 static method can access static data member and can change the value of it.
class sample
{
static void show()
{
System.out.println(“Java”);
}
}
Accessed by: sample.show(); // static method is accessed by classname.

19. Point out the justification of the statement “Java is platform independent”./How Java supports
platform independency?
 The meaning of platform independent is that, the java source code can run on all operating
systems.
 A compiler is a program that translates the source code for another program from a programming
language into executable code.
 This executable code may be a sequence of machine instructions that can be executed by the CPU
directly, or it may be an intermediate representation that is interpreted by a virtual machine. This
intermediate representation in Java is the Java Byte Code.

20. How 2-dimensional array in java can be declared and initialized?


 Array is a collection of similar type of elements that have contiguous memory location.
 It is a data structure and store only fixed set of elements in a java array.
 Array in java is index based, first element of the array is stored at 0 index
int[][] arr=new int[3][3];
intarr[][]={{1,2,3},{2,4,5},{4,4,5}};

21. Mention the various ways to overload the method.


When two or more methods within the same class that have the same name, but their parameter
declarations are different. The methods are said to be overloaded, and the process is referred to as method
overloading. Method overloading is one of the ways that Java supports polymorphism.
There are two ways to overload the method in java
1. By changing number of arguments
2. By changing the data type

13 mark

1. Characteristics of OOPS
2. Constructors
3. Package
4. Selection statements
5. Inheritance
6. Interface

You might also like