- Why do we write throws IOException after main()throws keyword followed by the exception name i.e. IOException in this case, is used to handle anomalous situations in a program. Throwing exceptions over a function body helps in preventing/correcting possible errors in java programs.
- What is an Object Oriented Programming (OOP) Language?An OOP language is one which follows OOP paradigm. An OOP language like C++, Java, PHP etc consists of classes which have data members and member functions. These languages use the OOP concepts ofAbstraction, Encapsulation, Polymorphism and Inheritance.
- What is data abstraction?Data Abstraction refers to the act of representing essential features without showing background details or explanations. It can be achieved by making use of private/protected methods in a class.
- What is encapsulation?Encapsulation is the wrapping up of data(data members) and functions(methods) into a single unit/block. A class is the example of using the concept of encapsulation.
- What is Inheritance? State different forms of Inheritance.The ability of a class to acquire certain characteristics(data members) or behaviour(methods) of another class is known as Inheritance. The class which derives data from another class is known as the derived or sub class and the class from which it derives is known as base or super class. The Different forms of inheritance are: Single, Multiple, Multilevel, Hybrid and Hierarchical.
- What is Polymorphism? How is it implemented?The ability of the data to be perceived in more than one form is known as polymorphism. It is implemented using function(constructor) overloading and operator overloading.
- Difference between for-loop and while-loop.For loop runs for a fixed number of times whereas while loop runs as long as the given condition is true.
- Difference between while-loop and do-while loop.Unlike while loop, a do-while loop runs as long as the given condition is true.
- Difference between iteration and recursion.In iteration, memory space once allocated is used repeatedly for computation whereas in recursion new memory space is allocated for each function call. This makes recursion slower than iteration.
- Difference between class and interface.A class consists of data members and functions which are defined using these data members. Whereas, an interfaceconsists of only function prototypes with no definition. The class which implements interface agrees to provide definition for all of its methods. An interface cannot be instantiated like classes. By default, the members of an interface are abstract andpublic.
- Difference between interface and abstract class.Abstract Class
Abstract classes are used to declare common characteristics of subclasses. An abstract class cannot be instantiated. It can only be used as a super class for other classes that extend the abstract class. Abstract classes are declared with the keyword abstract.
Interface
An Interface is used to define a generic template. Interfaces just specify the method declaration (implicitly public and abstract) and can only contain fields (which are implicitly public static final). Interface definition begins with a keyword interface. An interface may never contain method definitions. An interface cannot be instantiated. Multiple Inheritance is facilitated through interfaces in Java. A class that implements an interface must implement all of the methods described in the interface, or be an abstract class. - Difference between throw and throws keywords.
- Throws clause in used to declare an exception and throw keyword is used to throw an exception explicitly.
- If we see syntax wise than throw is followed by an instance variable andthrows is followed by exception class names.
- The keyword throw is used inside method body to invoke an exception and throws clause is used in method declaration (signature).
- The keyword throw is used inside method body to invoke an exception and throws clause is used in method declaration (signature). For example:
Throw: .... static{ try { throw new Exception("Something went wrong!!"); } catch (Exception exp) { System.out.println("Error: "+exp.getMessage()); } } .... Throws: public void sample() throws ArithmeticException{ //Statements ..... //if (Condition : There is an error) ArithmeticException exp = new ArithmeticException(); throw exp; ... }
- By using Throw keyword in java you cannot throw more than one exception but using throws you can declare multiple exceptions. For example:
Throw: throw new ArithmeticException("An integer should not be divided by zero!!") throw new IOException("Connection failed!!") Throws: throws IOException, ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException
- What does import java.io.* mean?import keyword is used to include a package in a program.
java.io is a pre-defined package in java that contains classes required in input/output (I/O) operations. *(asterisk) here acts as the wildcard i.e. all classes within the java.io package are imported. - Explain the line public static void main(String args[]).public meqdesc the function main can be accessed from anywhere i.e. its access is not limited.
static meqdesc the function can be called using its class name and there is no need to create an object of its class to call it.
void meqdesc null/empty. It meqdesc that the function is not returning any value.
main() is the function present in every java program. Every java program starts and ends within the main. - What is constructor overloading?Constructors are functions with the same name as that of its class. When several constructors with different signature are defined it is known as constructor overloading.
- What is a copy constructor?A constructor which receives an object is known as a copy constructor.
- What is the use of this keyword?this keyword is used to access the data members of a class.
- What is the difference between overloading and overriding?Overloading uses the concept of polymorphism where multiple functions with same name are allowed provided their signatures are different.
A method in a subclass hides or overshadows a method inherited from the super class if both methods have the same name and signature. This property is known as overriding the inherited method. - Explain super keyword.super keyword is used to access the members of base class from a derived class in inheritance.
- Explain recursive case and base case.recursive case consists of the problem that is to be solved. It contains the logic to solve a problem along with the function call. base case is the part of the problem whose solution is known to us.
For ex:- To calculate factorial of a number
we know that
0!=1
1!=1
this is the base case.
Also, the factorial of a number 'n' is calculated as
n!= n x (n-1)!
this part is known as the recursive case. - What is fall-through condition in switch-case?When break statement is missing in a switch statement, the control falls to the cases following the matched case. This is known as fall-through condition.
- What are wrapper classes?The classes corresponding to the primitive data types are known as wrapper classes. For ex:- For primitive data type int we have Integer class. Wrapper classes contain functions which are used in data manipulation.
this site is to help students to learn coding in java platform and qbasic platform. all programs are ICSE and ISC level. Java programs java python Python programs
ISC Q/ANS
Subscribe to:
Post Comments (Atom)
Second largest number in java using ternary operator
//Largest second number using ternary operator public class Main { public static void main(String[] args) { int a=5,b=6,c=7; int ...
-
import java.util.*; class riwi { public static void main(String[]args) { Scanner sc=new Scanner(System.in); System...
-
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 ...
-
import java.io.*; class snowball { public static void main()throws IOException { BufferedReader br = new BufferedReader(new InputStreamRead...
No comments:
Post a Comment
any problem in any program comment:-