SC 2
SC 2
faq:
=>we cannot declare local variables as 'static',because the static variables must
i
===================================================================
thi
=======
faq:
ipa
can we have Global variables in Java?
are within the class or within the Object or within the method.
===================================================================
sh
=====
ate
nk
Ve
*imp
class:
i
thi
1.nextByte()
2.nextShort()
ipa
3.nextInt()
4.nextLong()
5.nextFloat()
Ma
6.nextDouble()
7.nextBoolean()
sh
8.nextLine()
ate
=>we use the following syntax to create object for 'Scanner' class:
class Object.
Method Signature:
Method Signature:
i
public short nextShort();
thi
syntax:
ipa
Ma
3.nextInt() : This method is used to read int-data
Method Signature:
Method Signature:
Ve
syntax:
syntax:
i
6.nextDouble() : This method is used to read double-data
thi
Method Signature:
ipa
syntax:
syntax:
nk
Method Signature:
syntax:
program : DemoMethods3.java
import java.util.Scanner;
i
thi
class UserDetails
ipa
//Instance Variables memory in Object
String name,mId; Ma
long phNo;
sh
//Instance method
void getUserDetails()
ate
System.out.println("****UserDetails****");
nk
System.out.println("UserName="+name);
Ve
System.out.println("MailId="+mId);
System.out.println("PhoneNo="+phNo);
class DemoMethods3
{
i
System.out.println("Enter the UserName:");
thi
ud.name = s.nextLine();
ipa
ud.mId = s.nextLine();
Ma
System.out.println("Enter the PhoneNo:");
ud.phNo = s.nextLong();
ud.getUserDetails();
sh
ate
}
nk
o/p:
nit.V
9898981234
****UserDetails****
UserName=nit.V
PhoneNo=9898981234
i
thi
ipa
Ma
sh
ate
=================================================================
Assignment-1:
nk
SubClass : Product
=>code,name,price,qty
=>void getProduct()
MainClass : DemoMethods4.java
Assignment-2:
SubClass : BookDetails
=>bCode,bName,bAuthor,bPrice,bQty
i
=>void getBookDetails()
thi
MainClass : DemoMethods5.java
===================================================================
ipa
=====
Ma
sh
ate
nk
Ve