Java Quiz
Java Quiz
A class can be defined as a template/blueprint that describes the state/behavior that the object of
its type supports
QUESTION TWO
An object is an instance of a class. Objects have states and behaviors, for example a Car has color,
name, manufacturer,
QUESTION 3
String carName;
Int color;
String numberPlate;
Void topSpeed(){
Void mileage(){
QUESTION 4
A java method is a collection of statements that are grouped together to perform an operation.
When you call system.out.printl() method, for example, the system actually executes several
statements in order to display a message on the console.
example
Int min ;
Min = n2;
Else
Min = n1 ;
Return min;
QUESTION 5
Implements – used for implementing an interfaces. To implement an interface we must use the
keyword implements. In java you can implement more than one interface.
Extends – used for extending a class. In java we inherit fields and methods of a class by extending it
using the keyword extends. A class can only extend a maximum of one class only
QUESTION 6
Instance variables in java are non-static variables which are defined in a class outside any method,
constructor or a block
QUESTION 7
A constant variable is a variable whose value cannot change once it has been assigned.
QUESTION 8
Class variables also known as static variables are declared with the static keyword but outside a
method, constructor, or block.
QUESTION 9
In java return is a keyword used to exit from the method with or without a value. Every method is
declared with a return type and it is mandatory for java methods.
QUESTION 10
return a_value;
QUESTION 11
Java this keyword is used to refer the current instance of a method on which it is used
Class Outer;
Class inner{
Void foo() {
Outer O = outer.this;
QUESTION 12
Method overloading in java is when a class has multiple methods by same name but different
parameters
QUESTION 13
Class Adder {
Static int add ( int a , int b) { return a + b;}
Class TestOverloading {
System.out.println (Adder.add(11,11));
System.out.println (Adder.add(11,11,11));
}}
QUESTION 14
If a subclass {child class} has the same method as declared in the parent class, it is known as method
overriding.
In other words, if a subclass provides the specific implementation of the method that has been
declared by one of its parent class, it is known as method overriding.
QUESTION 15
// here we are calling the method of the parent class with child class object
Class vehicle {
Void run ( ) {
Obj.run () ;
}}
QUESTION 16
Constructor is a block of code that initializes the newly created object. A constructor resembles an
instance method in java but its not a method as it does not have a return type
Constructor has same name as the class and it looks like this in java code
My class(){