Oops Using Java - 2 Marks Important Qs With Ans Athabo
Oops Using Java - 2 Marks Important Qs With Ans Athabo
1. Simple: Java is a simple programming language and easy to understand because it does not contain
complexities that exist in prior programming languages.
3. Platform Independent: The design objective of Javasoft people is to develop a language that must work
on any platform. Here platform means a type of operating system and hardware technology.
4. Portable: The WORA (Write Once Run Anywhere) concept and platform-independent feature make Java
portable. Now using the Java programming language, developers can yield the same result on any
machine, by writing code only once.
When a package has imported, we can refer to all the classes of that package using their name directly.
The import statement must be after the package statement, and before any other statement.
A Local Applet is written on our own, and then we will embed it into web pages. Local Applet is developed
locally and stored in the local system.
A remote applet is designed and developed by another developer. It is located or available on a remote
computer that is connected to the internet.
The <param> tag in HTML is used to define a parameter for plug-ins which is associated with <object>
element. It does not contain the end tag.
But there are many differences between abstract class and interface that are given below.
Interface Abstract class
Interface can have only abstract methods. Since Abstract class can have abstract and non-abstract
Java 8, it can have default and static methods also. methods.
Interface supports multiple inheritance. Abstract class doesn't support multiple
inheritance.
Interface has only static and final variables. Abstract class can have final, non-final, static and
non-static variables.
Interface can't provide the implementation of Abstract class can provide the implementation of
abstract class. interface.
The interface keyword is used to declare interface. The abstract keyword is used to declare abstract
class.
break continue
The Break statement is used to exit from the loop The continue statement is not used to exit from
constructs. the loop constructs.
The break statement is usually used with the The continue statement is not used with the
switch statement, and it can also use it within the switch statement, but it can be used within the
while loop, do-while loop, or the for-loop. while loop, do-while loop, or for-loop.
18. What is string buffer class and how does it differ from string class?
Ans: A string buffer is like a String, but can be modified. At any point in time, it contains some particular
sequence of characters, but the length and content of the sequence can be changed through certain
method calls. String buffers are safe for use by multiple threads.
String Buffer is differ from string by following
❖ StringBuffer uses less memory as compared to the string.
❖ It prefers heap memory to store the objects.
❖ It cannot override equal() and hashcode() methods.
20. Define interface. Write the syntax for implementing an interface in a class
Ans: An interface is declared by using the interface keyword. It provides total abstraction means all the
methods in an interface are declared with the empty body, and all the fields are public, static and final by
default. A class that implements an interface must implement all the methods declared in the interface.
Syntax:
interface <interface_name> {
// declare constant fields
// declare methods that abstract
// by default.
}
21. What is static data member and static member function?
Ans:
Static Data Member
A static data member in C++ is a data member defined in a class that is not instantiated with each object
created of the class. Data members defined in a class are usually instantiated with every object created of
the class.
Syntax: Declaration within the class definition is done by using the keyword- static.
class scaler{
static int number;
};
Static Member Functions
Static member functions in C++ are the functions that can access only the static data members. These
static data members share a single copy of themselves with the different objects of the same class. A
function can be made static by using the keyword static before the function name while defining a class.
Syntax:
static returntype function_name(){
25. What is meant by controls and what are the different types of controls in AWT?
Ans: Controls are components that allow a user to interact with your application and SWT / AWT supports
the following types of controls: Labels, Push Buttons, Check Boxes, Choice Lists, Lists, Scrollbars, Text
Components.
System. out is a method in Java that prints a message to the standard output (typically the console) and
appends a newline character. It's widely used to display messages, data, and the results of operations
during the execution of a program.
class method
A template for creating or instantiating objects
A Function that exposes the behavior of an object
within a program
To initialize an array of arrays, you can use new keyword with the size specified for the number of arrays
inside the outer array. int[][] numbers = new int[3][]; specifies that numbers is an array of arrays that store
integers. Also, numbers array is of size 3, meaning numbers array has three arrays inside it.
38. What is Interface?
Ans: An interface in Java is a blueprint of a class. It has static constants and abstract methods.
The interface in Java is a mechanism to achieve abstraction. There can be only abstract methods in the
Java interface, not method body. It is used to achieve abstraction and multiple inheritance in Java.
Thread class:
Thread class provide constructors and methods to create and perform operations on a thread. Thread
class extends Object class and implements Runnable interface.
Runnable interface:
The Runnable interface should be implemented by any class whose instances are intended to be executed
by a thread. Runnable interface have only one method named run().