idiot4
:)
Homepage: https://idiot4.wordpress.com
Java Tutorial 13 – Visibility and Scope
Posted in Java on July 1, 2012
Visibility is how accessible methods and variables to other class is. We’ve used methods from other class in tutorial Multiple Class. Which was possible because all the method we used from other class was public. There are mainly three types of access specifier.
- Public
Every Public variable and method is accessible to all other class. - Protected
Protected elements are inheritable, means each child class has all the protected method that parent has and it only accessible between all it’s inheritance tree. - Private
Private elements are accessible only for class itself.
Lets have a cup of Example:
we will create 2 class parent class will have 1 public, 1 protected and 1 private int, and we will try to access these ints in its child class.
Parent:
Close Friends Can Now Track Your Fitness Successes (And Failures) On Path, With A Daily Sparkline From Nike+ Fuelband
Posted in News on June 30, 2012
Blavatar
Close Friends Can Now Track Your Fitness Successes (And Failures) On Path, With A Daily Sparkline From Nike+ Fuelband
YouTube’s Next New Creator Program Is Meant To Bring In The LOLs
Posted in News on June 30, 2012
Blavatar
YouTube’s Next New Creator Program Is Meant To Bring In The LOLs
Google Analytics Goes Mobile With App Analytics And An Android App
Posted in News on June 30, 2012
Google Analytics now on Android App !
Google Pumps Up Jelly Bean’s Face Unlock Feature With A New ‘Liveness Check’
Posted in News on June 30, 2012
Google Pumps Up Android’s (Jelly Bean) Face Unlock Feature With A New ‘Liveness Check’
YouTube And Google+ Grow Closer: All Users Can Now Switch Their Usernames To Their Google+ Profiles
Posted in News on June 29, 2012
All Users Can Now Switch Their Usernames To Their Google+ Profiles
Java Tutorial 12 – Constructors
Posted in Java on June 29, 2012
constructors are a special type of method which we can use to initialize Objects when we create it. If u do not use constructor, objects contains all the variables and methods, But Using constructor you can initialize values of variables. For example you can initialize some variables to zero or Strings to default values and etc. Lets Clear this with an example. Create two classes Tom and Jerry.
Tom:
public class Tom {
public static void main(String[] args){
Jerry object = new Jerry();
object.print();
}
}
Jerry:
public class Jerry {
int a;
String b;
public void print(){
System.out.println(“int a = “+a);
System.out.println(“String b = “+b);
}
}
Now if u run the Tom.java you will see the output like:
int a = 0
String b = null
Now if you want to initialize String b to some text say “Hi” and int a to value 5 whenever the new object is created, you can do it by creating constructor. There are some rules for it:
- Name of the constructor must be same as name of class.
- there is no other rule 😛
Now lets create constructor for Jerry class and initialize variables.
Jerry:
public class Jerry {
int a;
String b;
Jerry(){
a=5;
b = “Hi”;
}
public void print(){
System.out.println(“int a = “+a);
System.out.println(“String b = “+b);
}
}
!!!!! yap writing return type and access modifiers is optional. We can define Constructor by just Jerry(){ … }.
Now if you run the Tom.java you will see the output like:
int a = 5
String b = Hi
Here constructor initialized both variables when we created an object of Jerry.
catch you again later…
doubts are invited.
have a nice day.
Peace.
Gmail Now Has 425 Million Users, Google Apps Used By 5 Million Businesses And 66 Of The Top 100 Universities
Posted in News on June 29, 2012
Google Drive Now Has 10 Million Users: Available On iOS and Chrome OS
Posted in News on June 29, 2012