JavaBasics Practice Question and Answers
Java Practice Question and Answers
Java Variables and Data types
Find the Answers for the following Questions
- What is Literal? In Java.
- What data you have always written in double quotes ("").
- Class name should start with _______.
- Why to use variables.
- What datatype you used to store text data in java.
- To store integers, what datatype you use?
- What is the use of ++.
- What is the default method in java ?give the name.
- Difference between char and String?
- How to convert one data type to another in Java?
- How to store character data in a variable in java, give an example?
- How to declare float value, give an example?
- How many types of scopes available for variables?
- What are Escape sequence characters, give 2 examples.
- What symbols you can use in a variable name.
- What is the maximum length of the variable name.
- How do you comment multiple lines in Java?
Java Methods
- What is method? Where it is created.
- Types of methods in java
- How many types of user defined methods
- Write an example of predefined method
- What is method signature
- What is void will do in java method.
- What is method overloading in java
- Difference between static method and instance method
- How to call static method
- Where static variable, methods are stored in Java?
Java Classes with Answers
What is class
class, is a template for an object
- properties
- methods
- constructors
- blocks
- inner classes.
What is an object
- object is a copy/blue print of a class. It holds the data.
Why we use methods in class
- methods used to operate on object data.
What is the use of object
- To store data of an entity.
What is instantiating
- creating an object
Which operator used to create an object.
- new operator
- It points to an object. Using Class, object reference is created.
Ex. Student s1;
In which memory, object is created.
- heap memory
- by defautl all variable declared in class are belongs to object/instance.
What are class variables how you create them
- class variables stored in class itself. They created using static keyword.
How to set data to properties of an object
using set methods
ex. setName("John");
How to display data an of object
- using methods
- ex. getName()
What are the different ways to set data to an object.
- using method
- using constructor.
Types of Methods in java
Types of Constructors in java
What is this keyword
- this is reference to an object.
What is method overloading in class
- Same method name with different parameter-lists and different return type. Overloading occurs in the same class.
What are access modifiers
- controls the accessibility of the members in a class.
ex. public, private, protected, default
How many types of access modifiers
1. Access modifiers - ex. public,private,protected,default
2. Non access modifiers - static, final, abstract, transient, volatile etc.
Java Inheritance
What is Inheritance?
Creating a new class (derived class) from an existing class (base class).
Which keyword used to extend from one class to another
-- super keyword
Where 'super' keyword is used?
--Used to invoke parent class constructor from the child class.
What is method overriding
-- redefining parent class method in child class
how to do you implement multiple inheritance in java?
-- using interfaces
Interface start with --------- keyword
-- interface
Interface contains only method -------------------
-- declarations.
What keyword is used, to implement interface by child class
-- implements
All the interface method declarations must be a ---------
-- public
What is the rule while implementing interface by child class
-- All the methods must be implemented by child class.
What is abstract class
--partially implemented class is known as abstract class.
Which class cannot create an object
-- abstract class
what is Concrete class
-- fully implemented class
Comments
Post a Comment