Java Programming - Class Test 1
Java Programming - Class Test 1
Java Programming - Class Test 1
Class test 1
Answer: 1.Simplicity
2. Object Oriented
3. Platform Independence
4. Portable
6. Java is Robust
7. Security
8. Dynamic
2. Multilevel Inheritance
3. Hierarchical Inheritance
4. Multiple Inheritance
5. Hybrid Inheritance
Answer:
Try
{
//block of code to monitor for errors
}
Catch (ExceptionType1 ex0b)
{
//exception handler for ExceptionType1
}
Catch (Exception Type2 ex0b)
{
//exception handler for ExceptionType2
Java Programming
Class test 1
}
//
Answer:
Constructor is declared in side a class .
A constructor initializes an object immediately upon creation.
Constructors have the same name as the itself .
A constructor is automatically called when an object is created.
Types of constructor
1. Default Constructor
2. Parameterized Constructor
Answer: Class:
Answer:
Errors are the Wrongs that can make a program go wrong.
Types of errors :
Answer: A group of contiguous or related data items that share common name.
Stores a fixed sequential collection of elements of same data type .
Types of array :
Single Dimensional array(1-D)
Java Programming
Class test 1
4 marks
1. Explain the concept of platform independence and portability with respect to Java
language. (Note: Any other relevant diagram shall be considered).
Answer: Java is a platform independent language. This is possible because when a java program
is compiled, an intermediate code called the byte code is obtained rather than the machine code.
Byte code is a highly optimized set of instructions designed to be executed by the JVM which is
the interpreter for the byte code. Byte code is not a machine specific code. Byte code is a
universal code and can be moved anywhere to any platform. Therefore java is portable, as it can
be carried to any platform. JVM is a virtual machine which exists inside the computer memory
and is a simulated computer within a computer which does all the functions of a computer. Only
the JVM needs to be implemented for each platform. Although the details of the JVM will defer
from platform to platform, all interpret the same byte code.
Java Programming
Class test 1
Answer : Constructors are used to initialize an object as soon as it is created. Every time an object is
created using the ‘new’ keyword, a constructor is invoked. If no constructor is defined in a class, java
compiler creates a default constructor. Constructors are similar to methods but with to differences,
constructor has the same name as that of the class and it does not return any value. The types of
constructors are:
1. Default constructor
3. Parameterized constructor
4. Copy constructor
class test1
{ int i; boolean b;
byte bt;
float ft;
String s;
System.out.println(t.i);
System.out.println(t.s);
System.out.println(t.b);
System.out.println(t.bt);
Java Programming
Class test 1
System.out.println(t.ft);
} 2.Constructor with no arguments: Such constructors does not have any parameters. All the objects
created using this type of constructors has the same values for its datamembers.
int roll_no;
String name;
Student()
roll_no = 50;
name="ABC";
void display()
System.out.println("Name is : "+name);
s.display();
1. private
Java Programming
Class test 1
2. default
3. Protected
4. public
1) private access modifier: The private access modifier is accessible only within class.
2) default access specifier: If you don’t specify any access control specifier, it is default, i.e. it becomes
implicit public and it is accessible within the program.
3) protected access specifier: The protected access specifier is accessible within package and outside the
package but through inheritance only.
4) public access specifier: The public access specifier is accessible everywhere. It has the widest scope
among all other modifiers.
Answer :
Answer : Java Command Line Argument: The java command-line argument is an argument i.e. passed at
the time of running the java program.
The arguments passed from the console can be received in the java program and it can be used as an
input. So, it provides a convenient way to check the behaviour of the program for the different values.
You can pass N (1,2,3 and so on) numbers of arguments from the command prompt. Command Line
Arguments can be used to specify configuration information while launching your application. There is
no restriction on the number of java command line arguments. You can specify any number of
arguments Information is passed as Strings. They are captured into the String args of your main method
Java Programming
Class test 1
Simple example of command-line argument in java In this example, we are receiving only one argument
and printing it. To run this java program, you must pass at least one argument from the command
prompt.
class CommandLineExample
Answer:
Java Programming
Class test 1
7. Define Type Casting. Explain its types with syntax and example .
Answer:
Answer: