Java Basics

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Java runs on

Windows, Unix/Linux, Mac

What is the keyword used in java to create a new object

new

Reference variable types

object, array, string

What value is assigned to x as the result of executing the following code? int y = 3 y++ x=y++

4

Which statement is NOT true about java array?

Array in java is index based, first element of the array is stored at 1 index

What is the value of -32%6?

-5

What is the value of x after this code is run int x=3 int y=2 x+=(y+x*2);

11

Given the declaration: int[] ar={1,2,3,4,5}; What is the value of ar[3]

4

If we declare int []arr={1,2,3,4,5,6}; arr.length will return

6

Which statement is not correct out of all

A . a final variable means you cannot change its value B. a final method means you cannot override the method c. a final class means you cannont extend the class D. NONE OF THE ABOVE

What is a class in java?

A blueprint from which individual objects are created. A class can contain fields and methods to describe the behavior of an object

Statments

A class can have more than one constructor Each time a new object is created, at least one constructor will be invoked If you dont provide a constructor, java complier will create one for your A constructors return value must be void-FALSE

What is a class variable

A class variable are static variables within a class but not outside any method

Which statement is not correct?

A. Name of the program file should exactly match class name B. Java program processing starts from the main() method which is mandatory part of every java program C. Variables defined inside methods, constructors or blocks. The variable will be declared and initialized within the method and the variable will be destroyed when the method has completed. D. Instance variables are initialized when the class is instantiated. The variables belong to the instance of a class, this an object E. NONE OF THE ABOVE-CORRECT

Which statement is not correct?

A. the main rule of constructors is that they should have the same name as the class B. an overloaded method is just a different method that happens to have the same method name. C. Constructors can also be overloaded? D. NONE OF THE ABOVE

What stands true about default modifier of class members?

By default, variables, methods and constructors can be accessed by any class lying in the same package

What keyword is used for a subclass to acquire the properties of its parent class

Extends

Abstract classes may or may not contain abstract methods i.e., methods without body (public void get());)

If a class is declared abstract, it can be instantiated

This means that in order for the conditional to happen, either x must be less than 3 or y must be greater or equal to 4

If((x<3) | | (y>4))

When one class acquires the properties (methods and fields) of another, ________ occurs

Inheritance

What is an instance variable

Instance variables are variables within a class but outside any method

What is the role of the constructor

It creates an instance of a class

Which is NOT keyword in java

Sub. (keywords ARE super, this, abstract)

Java method passes by value, which means except

The java methodwill change the original value

The logic statement !(true) | | !(False) will return

True

Constructors

a class has only one constructor each time a new object is created, at least one constructor will be invoked the main rule of constructors is that they should have the same name as the class

A class is

an abstract definition of an object

Definition of object

an instance of a class

Syntax to declare a two-dimensional array?

dataType [][] arrayName dataType [] arrayName[]; dataType arrayName[][]; datatype arrayName; NOT

An array holds

different values of the same data type

Statements about final

final variable cannot be modified static final defines a constant final variable cannot be used in a static method-F

What loop will display each of the numbers in this array on a separate line float[] nums={1.1,2.2,3.3};

for {int i=0; i<3; i++} System.out.println(nums[i]);

Which is correct about declaring an integer array?

int [] arr=new int[10]; int []arr=new int[10]; int arr[]=new int [10]; NOT correct: int arr=new int[10];

Correct way to initialize an array?

int a[]={2,3,4,5};

If none of the private/protected/public is specified for a member that member

is only accessible by other classes of the same package

a reference variable only stores

memory address of the object

default value of any reference variable is

null

Legal declaration and definition of a method

void method(void){};

If you want your conditional to depend on two true conditions proper notion between boolean statements is

&&

A subclass can inherit everything from is suplass, including data, methods and constructor(s)

False

The statement !(7==7) will return

False

What is the default value for an array?

Null

What is true about private access modifer?

Variables, methods and constructors which are declared private can be accessed only by the members of the same class


संबंधित स्टडी सेट्स

Intermediate Accounting Week 11 Smartbook

View Set

American Gov Ch. 6 - supplemental

View Set

Chapter 52: Assessment of the GI system

View Set